cron run script B after the successful execution of script A - bash

Two bash scripts, A and script B
how to schedule cron to run script B after successful execution of script A.
***** /home/scripts/A.sh ; /home/scripts/B.sh
Above one will run simultaneously but i should run B.sh after script A finish execution successfully

command1 && command2
command2 would only be run, if command1 returns an exit status of zero.

Related

Pause script until command in other script is executed [Bash]

In script a I tell script b to execute a certain command.
Is there a way to pause script a until script b is done executing?
I don't want to use sleep, because every run of the script can be different.
Use:
wait <pid>
This will cause script A to wait for B to complete before continuing.

Running shell script commands sequentially in Jenkins

In Jenkins, I have created a job which runs many shell script commands:
command1
command2
...etc
command1 is an ssh command which calls a shell script file on another server machine. I have to wait until it is finished, and AFTER it, command2 should come.
So, how can I make sure that the script file on the other machine, started by command1, has already finished its jobs, when in the Jenkins job the next command (command2) is started?
Or, alternatively,how can I make sure that command2 won't be started until the shell script on the other machine (started by command1) has already finished?
You can check out "How to send many commands to shell and wait for the command behind ends" in order to chain commands and wait for their completion.
When you execute a command through an ssh session, you might have to wrap that command in a script able to loop/wait for the command completion.
See an example in "How can I make ssh wait until the command exits?".
Or (a simpler wraper): How do I know when a command run over ssh has finished?
#/bin/bash
$#
echo "==== Command Output Finished ===="
look for the string ==== Command Output Finished ==== in your I/O routines to determine where the boundary between command outputs are.
Or you can try isolate those commands in their own Jenkins shell build step.
(Not a different job, just a different build step within the same job)

How can i check the exit code of individual process running in parallel executed by GNU Parallel

I am having an array in linux shell script. Array contains list of commands in bash shell script.
For instance :
args =( "ls","mv /abc/file1 /xyz/file2","hive -e 'select * from something'" )
Now I am executing these commands in array using GNU parallel as bellow
parallel ::: "${args[#]}"
I want to check the status code of individual process when they finish. I am aware that $? will give me the number of process which have failed but I want to know the exit code of individual process. How can I catch the exit codes of individual processes executed in GNU parallel?
Use the --halt 1 option, which makes parallel quit on the halting command, while returning it's exit code. From man parallel:
--halt-on-error val
--halt val
How should GNU parallel terminate if one of more jobs fail?
0 Do not halt if a job fails. Exit status will be the
number of jobs failed. This is the default.
1 Do not start new jobs if a job fails, but complete the
running jobs including cleanup. The exit status will be
the exit status from the last failing job.
2 Kill off all jobs immediately and exit without cleanup.
The exit status will be the exit status from the
failing job.
1-99% If val% of the jobs fail and minimum 3: Do not start
new jobs, but complete the running jobs including
cleanup. The exit status will be the exit status from
the last failing job.
--joblog logfile
Logfile for executed jobs. Save a list of the executed jobs to logfile in the following TAB separated format: sequence number, sshlogin, start time as seconds since epoch, run time in seconds, bytes in files transferred, bytes in files returned, exit status, signal, and command run.

shell script to execute command2 after completion of command1 in unix

If I have a UNIX shell script which has some commands on each line that needs to be run, like
#!/bin/bash
command1
command2
command2 to be excuted only after completion of command1. how to achieve it
You've already done it. bash normally waits for each command to run before running the next command. If you end the command with an ampersand (&), then it runs the command in the background, but since you haven't done that, each command runs synchronously.

UNIX batch shell script - will current command execute only after previous command finishes execution

If I have a UNIX shell script which has some program on each line that needs to be run, like
#!/bin/bash
command1
command2
command3
command4
will command2 execute only after command1 execution finishes or are they run in parallel without waiting for the previous command to finish as each command is a separate process that needs to be executed.
The commands are run serially. To run them in parallel, append & to each line:
#!/bin/bash
command1&
command2&
command3&
command4&
wait

Resources