-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecuteAndLog.sh
More file actions
executable file
·52 lines (41 loc) · 928 Bytes
/
executeAndLog.sh
File metadata and controls
executable file
·52 lines (41 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /bin/csh -f
if("$1" == "") then
echo "Usage: executeAndLog.sh <LOG> <RUN> <CMD>";
exit
endif
set log = $1; shift;
set RUN = $1; shift;
if($log == "/dev/null") then
set tmpLog = "/dev/null";
else if(-e $log || -e $log.gz) then
exit
else if($RUN) then
set ID = "`hostname` $$";
echo $ID >>! $log
set tmpLog = "/tmp/$log:t.pid$$"
echo $ID >>! $tmpLog
set line = `head -1 $log`
if ( "$line" != "$ID" ) then
exit
endif
endif
set cmd = "";
while ("$1" != "")
set cmd = "$cmd $1"; shift;
end
echo @ $cmd
if($RUN) then
set start = `date`;
# LOG THE COMMAND
echo " @ " `hostname` "|" $start "|" $cmd "|" $log >> command.log
$cmd >>& $tmpLog;
set finish = `date`;
echo $cmd >> $tmpLog;
echo $start >> $tmpLog;
echo $finish >> $tmpLog;
if ( $log != "/dev/null" ) then
gzip -f $tmpLog
mv $tmpLog.gz $log.gz
rm $log
endif
endif