I have two scripts which are mentioned in execute.sh
Condition: I want script1.sh to complete before starting script2.sh (line 2) and script2.sh (on line 2) to complete before starting the script2.sh (on line 3)
Also there should be no errors in execution of line 1 and line 3 scripts while i expect errors returned in execution of line 2. Thus, i need a check at the end of the three lines if line 1 or line 3 returned errors (should display what returned error) execute.sh failed or else execute.sh was successful.
Condition: I want script1.sh to complete before starting script2.sh (line 2) and complete script2.sh (on line 2) before starting the script2.sh (on line 3)
This is normally the case. If your scripts contain no sort of exquisite process management features (sending parts of themselvs into background, using nohup or the like) they way you wrote it script1 should be executed, then, upon its completion, script2 should be started, etc..
What makes you think this is not the case?
Quote:
Originally Posted by mohtashims
Also there should be no errors in execution of line 1 and line 3 scripts while i expect errors returned in execution of line 2. Thus, i need a check at the end of the three lines if line 1 or line 3 returned errors (should display what returned error) execute.sh failed or else execute.sh was successful.
You can check the error code of a (any) process by querying the variable "$?", which is set after the completion of every command. Notice, though, that every other command re-sets this. For instance:
will show the error returned by that command, but
will not. In fact it will display the error returned from the (first) echo command, which is most probably 0.
There are also other commands which use the error code returned from a process:
"if" evaluates the return level from the command (which can be a single command or some compound, like a pipeline) and executes the "then"-branch if this returns 0, otherwise the else-branch. Substitute "some_command" with "/bin/true" or "/bin/false" (two commands, which always return 0 and 1 respectively) to see the effect.
Another caveat is that scripts notoriously "forget" to set an error code. For a script to set an exit code you need to explicitly mention it with the exit-statement. This, for instance:
will always exit with 0, regardless of what the commands return. A script returning an error would look like this:
This will execute "some_command" and return 1 if it fails, but if it succeeds it will also execute "other_command" and return 2 if this fails. If both succeed it will return 0.
Hi all,
Here is a portion of my script test.sh:
#!/bin/bash
tar -cf $name.tar $name && pbzip2 $name.tar
2-Sending .tar.bz2 to destination node
Please, i have a question. The execution of the second instruction is done, but i do not see the result of pbzip2
I have to send this... (2 Replies)
Dear friends,
I have a hundred or so videos I keep in a directory, but as the collection has grown anarchically in the past years I have at least 3 different situations:
a) one directory for each video and within it the video and any other accompaining files (mostly text files with my notes and... (5 Replies)
Hi,
I am having a shell script on Solaris 10 which has a while loop as shown below.
#!/usr/bin/ksh
#
while
do
sleep 60
done
Name of the shell script is coldcentric.sh. I executed script /DATAWAREHOUSE/LOAD/Scripts/coldcentric.sh from a command task in Informatica worklow as... (3 Replies)
Hello
I am seeing a weird behavior during the execution of the shell program.
The shell programs loops through a file which has a list of files. for each file the programs cats the file, pipes the output to sed command and then on to an awk program. But while execution, the order of... (3 Replies)
55,0 5,6 * * * myScript
This cron task will execute on 5:00AM, 5:55AM, 6:00AM and 6:55AM.
Is there any possibility to make it run only in the order specified
such as 5:55AM and 6:00AM (basically only on the 2 intervals) ? (1 Reply)
I am database guy and not very good at shell scripts. I am seeking help to sharp my script coding. I have 5 scripts
1. master script. I use this one to call other four scripts to do database work.
2. db_backup_1 and log_backup_1
3. db_backup_2 and log_backup_2
in master script, I want to... (4 Replies)
Hello,
I am writing a shell script in which i do ssh to remote server and count the number of files there and then exit. After the exit the shell script terminates which i believe is expected behavior. Can some one suggest me a way where even after the exit the script execution resumes.
... (2 Replies)
Dear All
I am trying to write a script to set the SGE job execution order. I named each job with 'job1', 'job2' and 'job3'. I want my script to do: When 'job1' execution is complete, 'job2' is executed; when both 'job1' and 'job2' are complete, 'job3' is executed.
First, I tried this... (0 Replies)
Hi all:
I have a problem with a C++ service runing on solaris 10. This service only set a signal on oracle table. When the service detect a cut off on the line (tcp/ip), trigger a cobol program for set the signal OFF. When the line is on again, the service trigger the same cobol program for set... (0 Replies)
I have the following script:
(echo -n `curl http://www.example.com/scores.txt | grep mylocation`; date +%Y%m%d%H%M%S) >> myscores.txt
This script works fine, except that it places the timestamp at the end of the file myscores.txt. How do add the timestamp as the first column and then a tab and... (4 Replies)