Warning

 

Close

Confirm Action

Are you sure you wish to do this?

Confirm Cancel
BCM
User Panel

Posted: 8/28/2017 11:59:50 AM EDT
This is the command as entered in the script. I get the output of the command, except for the completion data that "time" is supposed to show.  I know it's a syntax issue, just not seeing where I screwed up.

time rsync -aHu --progress --recursive --delete /source-dir_path /destination_dir_path >> /log_file_-path$DATE &
Link Posted: 8/28/2017 12:21:51 PM EDT
[#1]
Try using date instead of time. In my experience, on various *nixes, 'time' timed a process' execution duration. 'date' prints out the date and time.
Link Posted: 8/28/2017 12:22:12 PM EDT
[#2]
Double tap.
Link Posted: 8/28/2017 12:29:19 PM EDT
[#3]
Well, what I want is a log of the time it took to complete the command.

So, I think I've found the problem; BASH has a native time command and that is not the same as the OS's time command in /usr/bin.  Ive edited the script to change "time" to "command time" in order to use the OS's native time utility.  I need to check and see if I need to declare that command in my variables.
Link Posted: 8/28/2017 4:49:13 PM EDT
[#4]
having no idea what your script does, are you sure that it's not a weird oddity with backgrounding the command?  For example:


bladernr@galactica:~$ ./test.sh
Factor using BASH time
1234567889234567891: 142662263 8653780357

real0m0.003s
user0m0.000s
sys0m0.000s
factor using /usr/bin/time
1234567889234567891: 142662263 8653780357
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 1888maxresident)k
0inputs+0outputs (0major+74minor)pagefaults 0swaps
now again with backgrounding
factor using BASH time and backgrounding
factor using /usr/bin/time and backgrounding
bladernr@galactica:~$ 1234567889234567891: 142662263 8653780357

real0m0.003s
user0m0.000s
sys0m0.000s
1234567889234567891: 142662263 8653780357
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 1836maxresident)k
0inputs+0outputs (0major+75minor)pagefaults 0swaps

bladernr@galactica:~$ cat test.sh
#!/bin/bash


echo "Factor using BASH time"
time factor 1234567889234567891

echo "factor using /usr/bin/time"
command time factor 1234567889234567891

echo "now again with backgrounding"

echo "factor using BASH time and backgrounding"
time factor 1234567889234567891 &

echo "factor using /usr/bin/time and backgrounding"
command time factor 1234567889234567891 &
View Quote
Note that when using backgrounding the script exits with no output from those commands, they appear after the script has exited.  You should be able to use either the BASH time or the system command time within the script, just depending on the result you expect, at least in my own experience.  That said, I don't really background processes inside scripts.
Link Posted: 8/28/2017 10:47:44 PM EDT
[#5]
If you do not care about the output of your actual command:



$ { time sleep 1; } 2> time.output
$ cat time.output

real0m1.009s
user0m0.001s
sys0m0.002s
Link Posted: 9/5/2017 10:53:46 AM EDT
[#6]
Update since folks took the time out of their days to attempt to help and i appreciate that.  I tried "command time" long-command and it didn't work.  I stopped disking around with it and cleaned up the script as I had to get it cleaned up and ready very quickly.  Under a lot of pressure and very public scrutiny from my organization, the script ran perfectly Thursday night and saved the day during our emergency outage.

The backgrounding of the commands worked fine, allowed for multiple rsync streams to run at the same time.

Thanks to all for attempting to help.  I'm glad this is over.
Link Posted: 9/5/2017 11:02:29 AM EDT
[#7]
It prints its output to STDERR. So to log that...

time some_command 2>&1 >output.file
Link Posted: 9/5/2017 12:07:39 PM EDT
[#8]
Discussion ForumsJump to Quoted PostQuote History
Quoted:
It prints its output to STDERR. So to log that...

time some_command 2>&1 >output.file
View Quote
Yup, I did end up figuring that out but not implementing it as I needed to get the script running and tested quickly.
Close Join Our Mail List to Stay Up To Date! Win a FREE Membership!

Sign up for the ARFCOM weekly newsletter and be entered to win a free ARFCOM membership. One new winner* is announced every week!

You will receive an email every Friday morning featuring the latest chatter from the hottest topics, breaking news surrounding legislation, as well as exclusive deals only available to ARFCOM email subscribers.


By signing up you agree to our User Agreement. *Must have a registered ARFCOM account to win.
Top Top