F5F Stay Refreshed Software Operating Systems A Linux script to generate and show an IP address.

A Linux script to generate and show an IP address.

A Linux script to generate and show an IP address.

A
alejandrobo1
Posting Freak
877
11-18-2022, 09:25 PM
#1
I was working on a script for Linux that records and shows the IP address in the nano file called address. At the start of the file I added #!/bin/bash so Linux recognizes it as a script. Later I wrote ifconfig > plik.txt and used grep to find "inet" before redirecting the output to plik.txt. After giving the script executable rights with chmod + x adres I executed it: ./address. Despite following the usual steps, I keep receiving photos instead of the expected results. I think there might be an error in the script.
A
alejandrobo1
11-18-2022, 09:25 PM #1

I was working on a script for Linux that records and shows the IP address in the nano file called address. At the start of the file I added #!/bin/bash so Linux recognizes it as a script. Later I wrote ifconfig > plik.txt and used grep to find "inet" before redirecting the output to plik.txt. After giving the script executable rights with chmod + x adres I executed it: ./address. Despite following the usual steps, I keep receiving photos instead of the expected results. I think there might be an error in the script.

M
mp3matt
Member
151
11-26-2022, 05:58 AM
#2
It doesn't function properly. You're welcome to explore the hints related to spelling and permissions.
M
mp3matt
11-26-2022, 05:58 AM #2

It doesn't function properly. You're welcome to explore the hints related to spelling and permissions.

S
Skilled_Spirit
Junior Member
8
12-09-2022, 03:50 PM
#3
I understand the issue. I checked online about why it doesn't function, but I'm not sure what's causing the problem. When using the same letters in the terminal, it works, but the script commands don't execute as expected.
S
Skilled_Spirit
12-09-2022, 03:50 PM #3

I understand the issue. I checked online about why it doesn't function, but I'm not sure what's causing the problem. When using the same letters in the terminal, it works, but the script commands don't execute as expected.

A
astro73
Junior Member
19
12-09-2022, 04:22 PM
#4
The issue arises from entering the search term as "inet" without any characters.
A
astro73
12-09-2022, 04:22 PM #4

The issue arises from entering the search term as "inet" without any characters.

I
ISY_0815
Senior Member
566
12-23-2022, 11:50 AM
#5
The lines are designed to interpret and manipulate system information. The ">" symbol typically indicates comparison or filtering, suggesting the code checks conditions to extract specific data. You're right—filtering the output of commands like ifconfig can be an effective approach to isolate the desired details.
I
ISY_0815
12-23-2022, 11:50 AM #5

The lines are designed to interpret and manipulate system information. The ">" symbol typically indicates comparison or filtering, suggesting the code checks conditions to extract specific data. You're right—filtering the output of commands like ifconfig can be an effective approach to isolate the desired details.

P
panda_1973
Junior Member
5
12-23-2022, 08:24 PM
#6
Set the target device and destination file. Define the IP address variable. Extract the network IP from the device output. Save the result to the specified file.
P
panda_1973
12-23-2022, 08:24 PM #6

Set the target device and destination file. Define the IP address variable. Extract the network IP from the device output. Save the result to the specified file.

M
marcus02
Junior Member
3
12-24-2022, 12:07 AM
#7
#!/bin/bash
outputfile=/tmp/myip
ip -4 a l $(ip route | head -1 | awk '/default/ { print $5 }') |
awk '/inet/ { print $2 }' |
awk -F'/' {'print $1'} |
tee ${outputfile}
M
marcus02
12-24-2022, 12:07 AM #7

#!/bin/bash
outputfile=/tmp/myip
ip -4 a l $(ip route | head -1 | awk '/default/ { print $5 }') |
awk '/inet/ { print $2 }' |
awk -F'/' {'print $1'} |
tee ${outputfile}