Execute the first line from last


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute the first line from last
# 1  
Old 06-18-2010
Execute the first line from last

Hi,

I have a script xyz.sh and in this, following lines exists.

Code:
#!/bin/bash

./abc.sh PB
sleep 60
./abc.sh RA
sleep 60
./abc.sh GS
sleep 60
./abc.sh S
sleep 60
./abc.sh SI
sleep 60
./abc.sh DR
sleep 12000
./abc.sh CT
sleep 7200
./abc.sh DL
sleep 60
./abc.sh DE
sleep 68400

How to execute the first line " ./abc.sh PB" after last line. It should keep on repeating.
# 2  
Old 06-18-2010
You need a loop. ( this is an infinite loop )

Code:
while :
do
  ##do anything here
done

# 3  
Old 06-18-2010
Code:
(tail -1)

will give u the last line. i am not sure hw can u execute it.
u can use exec command and try executing that way it wil help. and if ur sure the last line has a sleep command then u can do.

Code:
exec `cat xyz.ksh | tail -n`

i am not very familiar with use of exec, just searched it on net. i think this will work. on my system when i execute this command. this is closing my window. so not sure if i m correect or not.

sorry i didnt read the last line.
# 4  
Old 06-18-2010
I should keep on the executing the script.
After sleep 68400, I should again call the ./abc.sh PB and next line and so on.
Execution should be something recursive. How can I do that
# 5  
Old 06-18-2010
As I mentioned,


Code:
#!/bin/bash

while :
do
 ./abc.sh PB
 sleep 60
 ./abc.sh RA
 sleep 60
 ./abc.sh GS
 sleep 60
 ./abc.sh S
 sleep 60
 ./abc.sh SI
 sleep 60
 ./abc.sh DR
 sleep 12000
 ./abc.sh CT
 sleep 7200
 ./abc.sh DL
 sleep 60
 ./abc.sh DE
 sleep 68400
done

# 6  
Old 06-18-2010
then what anchal is saying will work awesomely.

sandy do u wnt to call the same script in cronjob also?
then copy whole of ur script inside the while loop as shown above and it will run for like 4ever unless and untill some1 kills it. or system crashes :P
# 7  
Old 06-18-2010
Hi, I would use cron for that, e.g. (start timees by approximation, first job starting at 01:01 hours):
Code:
echo " 1  1 * * *  /path/to/abc.sh PB
 2  1 * * *  /path/to/abc.sh RA
 3  1 * * *  /path/to/abc.sh GS
 4  1 * * *  /path/to/abc.sh S
 5  1 * * *  /path/to/abc.sh SI
 6  1 * * *  /path/to/abc.sh DR
26  4 * * *  /path/to/abc.sh CT
26  6 * * *  /path/to/abc.sh DL
27  6 * * *  /path/to/abc.sh DE" | crontab

If you are not allowed to use cron, then look into nohup, e.g.:

Code:
nohup /path/to/xyz.sh &


Last edited by Scrutinizer; 06-18-2010 at 08:19 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

One Line Command how to use pipe statements to execute and comment on multiple possible outcomes

Hello Forum, I'm looking to expand the following command: INACTIVE_KERNELS=$(python -mplatform | grep -qi red && rpm -qa | grep '^kernel-' |grep -vE `uname -r` | paste -sd \; || echo "Not Red Hat Server") Currently this command will check if my server is RedHat server using the grep -qi... (6 Replies)
Discussion started by: greavette
6 Replies

2. Shell Programming and Scripting

Modifying bash script to take each line in a file and execute command

I need to modify a bash script to to take each line in a file and execute command. I currently have this: #!/bin/bash if ; then echo "Lipsa IP"; exit; fi i=1 ip=$1 while ; do if ; then rand=`head -$i pass_file | tail -1` user=`echo $rand | awk '{print $1}'` pass=`echo $rand | awk '{print $2}'`... (3 Replies)
Discussion started by: galford
3 Replies

3. Shell Programming and Scripting

sed working on command line but file unchanged when execute with Shell script

I have a simple task to replace unix line feed end of line characters with carriage returns. When I run the following “change file in place” sed instruction from the command line all the Line feeds are successfully replaced with Carriage returns. sed -i 's/$/\r/' lf_file.txt But that same... (1 Reply)
Discussion started by: hawkman2k
1 Replies

4. Shell Programming and Scripting

Read line by line and execute command

Hi ALL, I have a requirement like this. 1.GET ALL TABLE NAME (just table name) keep in file 2.Read line by line and get the count of table from tablename files. tablename detail has a sql statement "db2 select tabname from syscat.tables" (1 Reply)
Discussion started by: netdbaind
1 Replies

5. UNIX for Dummies Questions & Answers

Execute multiple comands on one single line

hi, I have a litle problem i wish to excute this comand : ./test.sh -e txt /home -l a so what it says is that "-e" shows me all the extenions that are ".txt" in "home" this works but then i wish that "-l" will show all files begining in this case with the letter "a" . Both comands work... (5 Replies)
Discussion started by: samirboss
5 Replies

6. Shell Programming and Scripting

execute by line based from file

Hi, i would like to know what command by not using FOR LOOP. For example file A #cat file A System1 System3 #cat file B echo "System1 is now up" echo "System2 is now up" echo "System3 is now up" echo "System4 is now up" echo "System5 is now up" echo "System6 is now up" Output:... (6 Replies)
Discussion started by: kenshinhimura
6 Replies

7. Shell Programming and Scripting

How to take input from the user from the command line and execute commands basedon that?

Hi, I am using solaris 10 and bash shell.Script execution follows below.Initially it will check whether a directory exists or not if does not exist it will create it.(This I have completed) Second step:I have four users say user1,user2,user3,user4.Script should prompt for the user id and... (11 Replies)
Discussion started by: muraliinfy04
11 Replies

8. Shell Programming and Scripting

How to read a file line by line and store it in a variable to execute a program ?

Hello, I am quite new in shell scripting and I would like to write a little scritp to run a program on some parameters files. all my parameters files are in the same directory, so pick them up with ls *.para >>dirafter that I have a dir file like that: param1.para param2.para etc... I... (2 Replies)
Discussion started by: shadok
2 Replies

9. Red Hat

How to execute linux script line by line

Hi All, I have created one startup.sh file. which contain below script. I want to start all service(meclipse, mycomputer,firefox..) with single shot. My problem is only one service can open at a time. If i close that particular service only second service will start. cd... (3 Replies)
Discussion started by: stsivaraj
3 Replies

10. Shell Programming and Scripting

How to execute the multiple line sql using shell script

Hi All, Please help me to write a shell script to execute the below sql query. select c.account_no,b.bill_no,a.pay_type,(b.total_due + b.recvd + b.adjusted + b.disputed + b.transferred) as amt_not_billed,d.cash_on_delivery, (select j.bill_no from billinfo_T y, bill_t j where... (1 Reply)
Discussion started by: girish.raos
1 Replies
Login or Register to Ask a Question