3 added 584 characters in body
source | link

If your Unix implements the fuser command, this would be the easiest way:

while [ "$(fuser nohup.out 2>/dev/null)" ]; do sleep 2; done
command2

Make sure you run it in the same directory as command1.

A bit of explanation:

When you run a command with nohup, a file named nohup.out is created to store both of the command standard output and error.

The command I suggested is monitoring this nohup.out file to see if it is still open. If that's the case, that means the first process, command1, is still running. In that case, the while loop waits for two seconds and try again. When command1 ends, the nohup.out file is no more used and the loop is left, allowing command2 to be run. Note that this won't work if another process happen to use nohup.out afterwards, like someone running tail -f nohup.out.


Edit: If you OS doesn't provide fuser, here is a portable way:

1: identify the process ID of the background process. If you just ran the nohup command, you can simply get it with this command if typed just after nohup:

pid=$!

Otherwise, use one of:

pgrep command1
ps -eo pid,comm| grep -w [c]ommand1
top

or whatever similar method and set the pid variable accordingly.

Once you you are done, run this command:

while kill -0 $pid; do sleep 2; done
command2 

It will wait for command1 to complete before launching command2.

If your Unix implements the fuser command, this would be the easiest way:

while [ "$(fuser nohup.out 2>/dev/null)" ]; do sleep 2; done
command2

Make sure you run it in the same directory as command1.

A bit of explanation:

When you run a command with nohup, a file named nohup.out is created to store both of the command standard output and error.

The command I suggested is monitoring this nohup.out file to see if it is still open. If that's the case, that means the first process, command1, is still running. In that case, the while loop waits for two seconds and try again. When command1 ends, the nohup.out file is no more used and the loop is left, allowing command2 to be run. Note that this won't work if another process happen to use nohup.out afterwards, like someone running tail -f nohup.out.

If your Unix implements the fuser command, this would be the easiest way:

while [ "$(fuser nohup.out 2>/dev/null)" ]; do sleep 2; done
command2

Make sure you run it in the same directory as command1.

A bit of explanation:

When you run a command with nohup, a file named nohup.out is created to store both of the command standard output and error.

The command I suggested is monitoring this nohup.out file to see if it is still open. If that's the case, that means the first process, command1, is still running. In that case, the while loop waits for two seconds and try again. When command1 ends, the nohup.out file is no more used and the loop is left, allowing command2 to be run. Note that this won't work if another process happen to use nohup.out afterwards, like someone running tail -f nohup.out.


Edit: If you OS doesn't provide fuser, here is a portable way:

1: identify the process ID of the background process. If you just ran the nohup command, you can simply get it with this command if typed just after nohup:

pid=$!

Otherwise, use one of:

pgrep command1
ps -eo pid,comm| grep -w [c]ommand1
top

or whatever similar method and set the pid variable accordingly.

Once you you are done, run this command:

while kill -0 $pid; do sleep 2; done
command2 

It will wait for command1 to complete before launching command2.

2 added 634 characters in body
source | link

If your Unix implements the fuser command, this would be the easiest way:

while [ "$(fuser nohup.out 2>/dev/null)" ]; do sleep 2; done
command2

Make sure you run it in the same directory as command1.

A bit of explanation:

When you run a command with nohup, a file named nohup.out is created to store both of the command standard output and error.

The command I suggested is monitoring this nohup.out file to see if it is still open. If that's the case, that means the first process, command1, is still running. In that case, the while loop waits for two seconds and try again. When command1 ends, the nohup.out file is no more used and the loop is left, allowing command2 to be run. Note that this won't work if another process happen to use nohup.out afterwards, like someone running tail -f nohup.out.

If your Unix implements the fuser command, this would be the easiest way:

while [ "$(fuser nohup.out 2>/dev/null)" ]; do sleep 2; done
command2

Make sure you run it in the same directory as command1.

If your Unix implements the fuser command, this would be the easiest way:

while [ "$(fuser nohup.out 2>/dev/null)" ]; do sleep 2; done
command2

Make sure you run it in the same directory as command1.

A bit of explanation:

When you run a command with nohup, a file named nohup.out is created to store both of the command standard output and error.

The command I suggested is monitoring this nohup.out file to see if it is still open. If that's the case, that means the first process, command1, is still running. In that case, the while loop waits for two seconds and try again. When command1 ends, the nohup.out file is no more used and the loop is left, allowing command2 to be run. Note that this won't work if another process happen to use nohup.out afterwards, like someone running tail -f nohup.out.

1
source | link

If your Unix implements the fuser command, this would be the easiest way:

while [ "$(fuser nohup.out 2>/dev/null)" ]; do sleep 2; done
command2

Make sure you run it in the same directory as command1.