LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-24-2015, 11:03 PM   #1
Ben Wang
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Rep: Reputation: Disabled
Get the time when nohup R program finishes


I want to get the time when program starts and finishes. But it always show the same time. Here is my shell script. But it always show that `START TIME` is same as `END TIME`.
Code:
host_list=("c15-0330-01.ad.mtu.edu" "c15-0330-02.ad.mtu.edu" "c15-0330-03.ad.mtu.edu" "c15-0330-04.ad.mtu.edu")
program=("L_1" "L_4" "L_3" "L_4")
subject="The job is finished"
START=$(date +"r")
address="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"
ssh -f "${host_list[0]}" "cd '$address' && nohup Rscript '${program[0]}.R' > '${program[0]}_sh.txt';echo 'The job\n $address\n${program[0]} is finished\nSTART TIME = $START\n' END TIME =`date +"%r"` | mutt zwang10@mtu.edu -s '${host_list[0]} - Job ${program[0]}.R finished' -a '$address/${program[0]}_sh.txt';"

Last edited by Ben Wang; 04-24-2015 at 11:28 PM.
 
Old 04-25-2015, 01:45 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
I assume that is the start time, so you can see the the part ... END TIME =`date +"%r"` was executed at the time of invocation of the ssh command. I think you need to split it into 2 parts:
Code:
....
START=$(date +"r")
address="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"
ssh -f "${host_list[0]}" "cd '$address' && nohup Rscript '${program[0]}.R' > '${program[0]}_sh.txt'"
END=$(date +"r")
echo "The job\n $address\n${program[0]} is finished\nSTART TIME = $START\n' END TIME = $END" | mutt zwang10@mtu.edu -s "${host_list[0]} - Job ${program[0]}.R finished" -a "$address/${program[0]}_sh.txt"
(not tested)
It will execute the echo and mutt on the local host, and your original example executed them on the remote host (if that counts).
 
1 members found this post helpful.
Old 04-25-2015, 01:58 AM   #3
Ben Wang
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
I assume that is the start time, so you can see the the part ... END TIME =`date +"%r"` was executed at the time of invocation of the ssh command. I think you need to split it into 2 parts:
Code:
....
START=$(date +"r")
address="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"
ssh -f "${host_list[0]}" "cd '$address' && nohup Rscript '${program[0]}.R' > '${program[0]}_sh.txt'"
END=$(date +"r")
echo "The job\n $address\n${program[0]} is finished\nSTART TIME = $START\n' END TIME = $END" | mutt zwang10@mtu.edu -s "${host_list[0]} - Job ${program[0]}.R finished" -a "$address/${program[0]}_sh.txt"
(not tested)
It will execute the echo and mutt on the local host, and your original example executed them on the remote host (if that counts).
I tried you code as following
Code:
host_list=("c15-0330-01.ad.mtu.edu" "c15-0330-02.ad.mtu.edu" "c15-0330-03.ad.mtu.edu" "c15-0330-04.ad.mtu.edu")
program=("L_1" "L_4" "L_3" "L_4")
subject="The job is finished"
START=$(date +"%r")
address="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"
ssh -f "${host_list[0]}" "cd '$address' && nohup Rscript '${program[0]}.R' > '${program[0]}_sh.txt'"
END=$(date +"r")
echo "The job\n $address\n${program[0]} is finished\nSTART TIME = $START\n' END TIME = $END" | mutt zwang10@mtu.edu -s "${host_list[0]} - Job ${program[0]}.R finished" -a "$address/${program[0]}_sh.txt"
But it sends me email when the program starts. When program finishes, it does not send me email. Here is the email
Attached Thumbnails
Click image for larger version

Name:	temp.JPG
Views:	6
Size:	63.4 KB
ID:	18251  
 
Old 04-25-2015, 02:54 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
looks like it depends on that Rscript but we know nothing about that.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
break while [...] loop when a program finishes throughthegreens Linux - Newbie 6 02-18-2010 12:12 PM
problem with nohup command and nohup file size vbseeker Linux - General 1 09-17-2006 12:36 PM
How do you automatically power off after a program finishes? cscott Linux - Software 7 03-14-2005 04:36 AM
Kdevelop splash screen finishes loading then program crashes BluePyre Linux - Software 1 08-25-2004 02:51 PM
How to nohup an already running program ? fluppi Linux - General 0 06-29-2004 04:47 AM


All times are GMT -5. The time now is 08:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration