How to get a timestamp when running nohup & from a shell?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to get a timestamp when running nohup & from a shell?
# 8  
Old 06-12-2014
Quote:
Originally Posted by newbie_01
Hi,

I want to be able to use several nohup & in the shell script so as not having to wait for the one cp to complete to proceed with the next cp.

But as you pointed I can take out the nohup and run nohup the shell itself and I will get the timestamp.

Just want to make sure I understand what you mean by not using nohup &. If let's say I have several scripts name x1.sh, x2.sh that contains line like below:

Code:
#!//bin/ksh
x1.sh
date
cp -rp /app/source/dir1 /app/target/dir1
date

#!//bin/ksh
x2.sh
date
cp -rp /app/source/dir2 /app/target/dir2
date

Then I should be able to run each of them as below and get the date output, is that correct?

Code:
nohup x1.sh & 1>x1.out 2>&1
nohup x2.sh & 1>x1.out 2>&1

Thanks in advance.
Right idea, wrong syntax. The order of redirections matter. The redirections have to come before the ampersand that terminates the command. You don't want both scripts writing dates to the same file or you won't know which dates came from which commands (assuming you used >> instead of >; using > may cause you to just get one date from one script and one date from the other script and you won't know which date came from either script).

The following probably does what you want:
Code:
nohup x1.sh 2>&1 >x1.out&
nohup x2.sh 2>&2 >x2.out&

Also note that in your scripts:
Code:
#!//bin/ksh

will use /bin/ksh to interpret the script on some systems and will try to use/ksh from a machine on your network with hostname bin on other systems. Use:
Code:
#!/bin/ksh

instead.

And, in both cases, I'm assuming that the 2nd line you show in the scripts:
Code:
x1.sh
 and
x2.sh

is the name of the file containing the other lines in the script; not a line of code to be executed.
# 9  
Old 06-12-2014
Hi,

BTW, I tried as below

Create the following shell scripts.

data.ksh:

Code:
#!/bin/ksh

date
timex cp -pr /copy/data /db/devdb
date

index.ksh:

Code:
#!/bin/ksh

date
timex cp -pr /copy/index /db/devdb
date

Then I created a script called x.ksh as below:

Code:
#!/bin/ksh
nohup data.ksh  & 1>data.ksh.out  2>&1
nohup index.ksh & 1>index.ksh.out 2>&1

Then I run x.ksh
I am hoping to get some output from the .out file but I got nothing

I tried running the nohup manually from the command line. Same result, i.e. blank .out files.

Or do I simply have the first & in the wrong place Smilie
# 10  
Old 06-12-2014
Quote:
Originally Posted by newbie_01
Hi,

BTW, I tried as below

Create the following shell scripts.

data.ksh:

Code:
#!/bin/ksh

date
timex cp -pr /copy/data /db/devdb
date

index.ksh:

Code:
#!/bin/ksh

date
timex cp -pr /copy/index /db/devdb
date

Then I created a script called x.ksh as below:

Code:
#!/bin/ksh
nohup data.ksh  & 1>data.ksh.out  2>&1
nohup index.ksh & 1>index.ksh.out 2>&1

Then I run x.ksh
I am hoping to get some output from the .out file but I got nothing

I tried running the nohup manually from the command line. Same result, i.e. blank .out files.

Or do I simply have the first & in the wrong place Smilie
As I said before; you simply have every redirection and the ampersand in the wrong place. Try:
Code:
#!/bin/ksh
nohup data.ksh 2>&1 >data.ksh.out&
nohup index.ksh 2>&1 >index.ksh.out&

First, redirect the standard error output from the script to the same file descriptor that gets standard output from the script (2>&1). Then redirect the standard output from the script to a file for that script (>filename). Then run the command in the background (&).
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between & and nohup &

Hi All, Can anyone please help me understanding what the difference between the below two? 1. script.sh & 2. nohup script.sh & (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

2. UNIX for Advanced & Expert Users

Running process in nohup

Hi All, I am facing issue in running a process in nohup. I ran a process in terminal since it is taking too long to complete I need to make it as background and nohup. I tried below and was able to make it in back ground 1. Cntrl + Z 2. bg I am using Korn Shell so disown is not working... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

3. Shell Programming and Scripting

How to pause process running under nohup?

Hi ALL, Is there any way to pause a running process under nohup ? I have fired a build commands with required flags under nohup as below. now how can I pause the started build process. nohup make DEVICE=ap DEBUG=1 & I understand we can use ctrl + z to pause a foreground process... (3 Replies)
Discussion started by: useless79
3 Replies

4. UNIX for Dummies Questions & Answers

How to restrict the execution of same script if it is running already in nohup?

Hi, How can i restrict the execution of same script if it is running already in nohup Thanks (1 Reply)
Discussion started by: ranabhavish
1 Replies

5. Shell Programming and Scripting

Shell running with nohup not work, but with sh command yes..

why, when i run my shell with sh command it run without problem, but when run with nohup nombreshell.sh $ command not run correctly... values ​​obtained from database are not displayed in the csv file. My shell do that: 1° data base access with sqlplus: read_sql_stmt() { typeset stmt=$1... (3 Replies)
Discussion started by: joaco
3 Replies

6. Shell Programming and Scripting

Error while running script using nohup

Hi, I am running the below script. When i run the script normally it executes fine but when i run the same script using nohup it throws an error as getStatus.sh: syntax error at line 3: `(' unexpected . Can you let me know why it is so? while do . $(dirname $0)/include.sh cd... (2 Replies)
Discussion started by: vignesh53
2 Replies

7. UNIX and Linux Applications

nohup and & versus functions

when i have a function definition and function call in my script , i am unable to run my script in background with nohup.. Help me out please..... (3 Replies)
Discussion started by: venugopalsmartb
3 Replies

8. AIX

Query on running script with nohup

Hi, I'm trying to run database restore script with the nohup command as it will run for long hours since if I run it normally, the putty session will become inactive and the restore gets terminated. The command I use is nohup db2 -tvf FBR_NODE0000.scr -z FBR_NODE0000.log & But the problem is... (2 Replies)
Discussion started by: vkcool.17
2 Replies

9. UNIX for Dummies Questions & Answers

nohup & mpiexec problems

Hi everyone - I'm trying to start a run of LAMMPS (which takes an input file) with mpiexec on multiple processors. I want to combine this with nohup so that I can log off the node. I've used the syntax below successfully on one cluster, but it doesn't work on the new one I'm using. Any... (0 Replies)
Discussion started by: erin85
0 Replies

10. Shell Programming and Scripting

Execute Script using nohup and &

Hi all, I have one script test.sh for which I pass two arguments. In the same script I need to submit this script in background using nohup. My script like this and it is working in HP-UX os but not Solaris. #! /bin/sh if then MTR_PID=$$ export MTR_PID echo "test.sh $1 $2... (3 Replies)
Discussion started by: sridhar_423
3 Replies
Login or Register to Ask a Question