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?
# 1  
Old 06-11-2014
How to get a timestamp when running nohup & from a shell?

Hi,

I am running nohup cp & in a shell script.

How do I get a timestamp so I can get a timing of how long the copy took?

Roughly, the script does something like below:

Code:
date
nohup cp -rp /files/source /files/target &
date

I am mainly wanting to know how long it took for the copy to finish. The directory/ies that I am copying is between 10-100GB.

Please advice. Thanks
# 2  
Old 06-11-2014
One way is to redirect output to a file and then check the time of the file after the command has completed.

Code:
date
nohup cp -rp /files/source /files/target > results_of_copy.log 2>&1 &

# 3  
Old 06-11-2014
try
Code:
nohup time cp -rp /files/source /files/target > test.log &

# 4  
Old 06-11-2014
Putting a command in the background means that you lose the flow. Your initial:-
Code:
date
nohup cp -rp /files/source /files/target &
date

.... will just give you two timestamps almost immediately sequentially and your script will continue whilst the copy make still be progressing.

What are you actually after? If you keep the copy in the foreground of your script (take off the nohup and the &) then you will get the correct before & after times.

For a marker telling you the elapse (and other info) just use this:-
Code:
date
time cp -rp /files/source /files/target
date


I hope that this helps



Robin
# 5  
Old 06-11-2014
Have you tried using rsync instead of cp? I usually do "rsync -av"
which will tell you how log the file took to copy.

Code:
$ rsync -av /etc/oratab .
building file list ... done
oratab

sent 858 bytes  received 42 bytes  1800.00 bytes/sec
total size is 736  speedup is 0.82

You can add --stats to get even more information,
plus you can add compression with --compress if you want

Code:
$ rsync -av --stats --compress /etc/oratab .
building file list ... done

Number of files: 1
Number of files transferred: 0
Total file size: 736 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 60
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 76
Total bytes received: 20

sent 76 bytes  received 20 bytes  192.00 bytes/sec
total size is 736  speedup is 7.67

# 6  
Old 06-11-2014
You could also try:
Code:
nohup sh -c 'date;cp -rp /files/source /files/target;date' 2>&1 > cplog &

This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 06-11-2014
Quote:
Originally Posted by rbatte1
Putting a command in the background means that you lose the flow. Your initial:-
Code:
date
nohup cp -rp /files/source /files/target &
date

.... will just give you two timestamps almost immediately sequentially and your script will continue whilst the copy make still be progressing.

What are you actually after? If you keep the copy in the foreground of your script (take off the nohup and the &) then you will get the correct before & after times.

For a marker telling you the elapse (and other info) just use this:-
Code:
date
time cp -rp /files/source /files/target
date

I hope that this helps



Robin
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.
 
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