Execute shell script even if the first script fails


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute shell script even if the first script fails
# 1  
Old 07-31-2012
Execute shell script even if the first script fails

All,

I executing a perl script and shell script from a master shell script. i will execute the perl script first and have to execute the shell script after the completion of perl execution. Below is the code i use for it,
Code:
script_root='/dev/scripts'
/usr/bin/perl -S $script_root/test.pl; $script_root/test.sh

This is working fine. But if add redirect to log for the perl script, i get the below error
Code:
syntax error near unexpected token `;'


Last edited by vel4ever; 07-31-2012 at 04:34 AM.. Reason: typo
# 2  
Old 07-31-2012
But if add redirect to log for the perl script, i get the below error

post the code of redirection
# 3  
Old 07-31-2012
Please find it here,
Code:
/usr/bin/perl -S $script_root/test.pl >> log/perl_srt.log_$(date +\%F) 2>&1 &; $script_root/test.sh

# 4  
Old 07-31-2012
Quote:
Originally Posted by vel4ever
Please find it here,
Code:
/usr/bin/perl -S $script_root/test.pl >> log/perl_srt.log_$(date +\%F) 2>&1 &; $script_root/test.sh

you are executing the perl script in background.

you can do like this..

Code:
 
/usr/bin/perl -S $script_root/test.pl >> log/perl_srt.log_$(date +%F) 2>&1
wait
$script_root/test.sh

# 5  
Old 07-31-2012
Thank you. Will it execute test.sh even if test.pl fails and returns exit 1.
# 6  
Old 07-31-2012
Code:
 
$ cat f.sh
#!/bin/bash
echo "Shell Script"
exit 1
 
$ cat f.pl
#!/bin/perl
print "PERL Script";
exit 1;
 
$ cat g.sh
#!/bin/bash
bash f.sh
wait
perl f.pl
echo "Complete"
 
$ bash g.sh
Shell Script
PERL ScriptComplete

This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies

2. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

3. Shell Programming and Scripting

How to exit from shell script if above condition fails?

HI cd ${back_home} if above back_home does not exist, then script shoul exit. Please let us know how to do that (7 Replies)
Discussion started by: buzzme
7 Replies

4. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

5. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

6. Shell Programming and Scripting

Execute unix shell script to text file using the script

Hi all, I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script? Thanks i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
Discussion started by: mastercar
4 Replies

7. Shell Programming and Scripting

why shell script fails?

hi , i m trying to run a shell script automatically , some time it works fine but some time it fails , what could be the problem . If anybody have an idea about this problem then reply . Thanks in advacne (4 Replies)
Discussion started by: tahir23
4 Replies

8. Shell Programming and Scripting

why shell script fails

hi .. I have automate some process on unix through sehll script . but i don't know there is some problem in scripts, some time shell script works and some time it fails. so my query is that "Why shell script fails some times?" thanks (4 Replies)
Discussion started by: tahir23
4 Replies

9. UNIX for Dummies Questions & Answers

To call/execute a shell script from a shell script

Hi , I have 4 shell scripts a.ksh b.ksh -> depends on a.ksh success -> log into b.log c.ksh -> depends on b.ksh success -> log into c.log d.ksh -> depends on c.ksh success -> log into d.log I will have to write main.ksh ( execute a.ksh , log into a.log if a.ksh= success, execute... (1 Reply)
Discussion started by: konark
1 Replies

10. Shell Programming and Scripting

how to execute a batch script from shell script

Hi, I am new to shell scripting. Can anyone tell how to invoke a batch program from my shell script thnx (1 Reply)
Discussion started by: lakshmis10
1 Replies
Login or Register to Ask a Question