LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   shell script read line from file, use it in command (https://www.linuxquestions.org/questions/programming-9/shell-script-read-line-from-file-use-it-in-command-666484/)

DiGiGoth 08-30-2008 12:25 PM

shell script read line from file, use it in command
 
i need a script to read the first line from a text file which contains the ip address of my box, and use it in the command
#ez-ipupdate -a ip.ip.ip.ip

where ip.ip.ip.ip is the ip read from the file.txt

i think should read the lint to a var, and use it in the command ?

can someone write a whole script ?
cuz i'm new to shell scripts

thnx

i tryed.. i did something like this


#!/bin/bash
echo Updating dynamic host
wget -N whatismyip.com/automation/n09230945.asp
autoip='head -n 1 n09230945.asp'
echo $autoip

-
its not done yet , but i already have error
./autoip: command not found

though bash exists in path !!
user@ubuntu7:~$ whereis bash
bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz

zaichik 08-30-2008 12:49 PM

Try this:
Code:

#!/bin/bash
echo Updating dynamic host
wget -q whatismyip.com/automation/n09230945.asp
autoip=`head -n 1 n09230945.asp`
echo $autoip

Maybe "command not found" is referring to wget; are you sure that is installed?

DiGiGoth 08-31-2008 10:31 AM

still the same !
 
still the same, u only changed "wget" to quiet by -q !


user@ubuntu7:~$ ./autoip
-bash: ./autoip: Permission denied
user@ubuntu7:~$ sudo ./autoip
sudo: ./autoip: command not found
user@ubuntu7:~$

and yes, wget is installed !

Nylex 08-31-2008 10:43 AM

Quote:

Originally Posted by DiGiGoth (Post 3265246)
user@ubuntu7:~$ ./autoip
-bash: ./autoip: Permission denied

Your script needs executable permissions. Use chmod to set the correct perms.

DiGiGoth 08-31-2008 10:57 AM

thnx
 
thnx alot !! ;]
it worked,

zaichik 08-31-2008 12:08 PM

Actually, no, I also changed
Code:

echo $a
(which you had in your pre-edited version) to
Code:

echo $autoip
and changed
Code:

autoip='head -n 1 n09230945.asp'
to
Code:

autoip=`head -n 1 n09230945.asp`
(single quotes to backticks).

You're welcome.


All times are GMT -5. The time now is 08:25 AM.