LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2008, 12:25 PM   #1
DiGiGoth
LQ Newbie
 
Registered: Sep 2006
Posts: 17

Rep: Reputation: 0
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

Last edited by DiGiGoth; 08-31-2008 at 10:32 AM.
 
Old 08-30-2008, 12:49 PM   #2
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
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?
 
Old 08-31-2008, 10:31 AM   #3
DiGiGoth
LQ Newbie
 
Registered: Sep 2006
Posts: 17

Original Poster
Rep: Reputation: 0
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 !
 
Old 08-31-2008, 10:43 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by DiGiGoth View Post
user@ubuntu7:~$ ./autoip
-bash: ./autoip: Permission denied
Your script needs executable permissions. Use chmod to set the correct perms.
 
Old 08-31-2008, 10:57 AM   #5
DiGiGoth
LQ Newbie
 
Registered: Sep 2006
Posts: 17

Original Poster
Rep: Reputation: 0
thnx

thnx alot !! ;]
it worked,

Last edited by DiGiGoth; 08-31-2008 at 10:59 AM.
 
Old 08-31-2008, 12:08 PM   #6
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 07:07 PM
How to read a single line from a text file into a shell script. SkipHuffman Linux - Software 2 08-16-2006 03:10 PM
command or shell script to print line range from file minil Programming 3 12-28-2005 09:05 AM
shell script that read each line separatly xpucto Programming 6 09-20-2005 09:06 AM
Shell Script to read 500files from the command line saravanan1979 Programming 1 09-22-2004 10:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration