Shell script with html form
Hi,
I have wrote script. a. If job running more than 3 hours i need to send some html link to user and need to ask kill or not to kill #!/bin/sh export SGE_ROOT=/opt/sge source /opt/sge/default/common/settings.sh #Current time with converting to seconds c_time=`date +"m:%d:%y"` C_time=`date +%s -d ${time}` #Get Job number,user and start time to file qstat -u "*" | grep "sim" > qstatfile while read line do #Job start time s_time=`echo "$line" | awk ' { print $7 } '` #Convert to seconds S_time=`date +%s -d ${s_time}` DIFFSEC=`expr ${S_time} - ${C_time}` if [ "$DIFFSEC" >= "10800" ] U_name=`echo "$line" | awk ' { print $4 } '` job_id=`echo "$line" | awk ' { print $1 } '` echo -e "Hi $U_name,\n Your job ID $job_id is running more than 3 hours. Shall we delete JOB ID $job_id? Click your option in below link | mail -s "your subject" $U_name@xyz.com done < qstatfile I want to send a output to user using html and with yes to kill and No to keep If user select Yes (kill) I want kill job using qdel $job_id. Please help me |
html link? You will need web server to work with and also you need to configure it to be able to kill that process. Or do you have another idea?
|
For that issue cgi-bin was made
in your website root under cgi-bin folder ,generate random bash scripts run by root user to kill that process or whatever is convenient after 3 hours send link yourdomain.com/cgi-bin/script.sh to your counterpart and make sure that once that script is ran , it self destroying. Make sure cgi-bin is ok within virtualhost or what webserver conf file you got there |
#!/bin/sh
export SGE_ROOT=/opt/sge source /opt/sge/default/common/settings.sh #Current time with converting to seconds c_time=`date +"m:%d:%y"` C_time=`echo "$c_time" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }'` qstat -u "*" | grep "sim" | grep " r " > qstatfile while read line do #Job start time S_time=`echo "$line" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }'` #Get Diff time b/w start and current time DIFFSEC=`expr ${S_time} - ${C_time}` #More than 3 hours if [ "$DIFFSEC" -gt 10800 ]; then U_name=`echo "$line" | awk ' { print $4 } '` job_id=`echo "$line" | awk ' { print $1 } '` echo -e "Hi $U_name,\n Your job ID $job_id is running more than 3 hours.\n--->Click below link to keepalive \n http://vncin14/cgi-bin/action.sh?jobid=$job_id&action=keep-alive\n--->To kill this job ID $job_id click below link\n http://vncin14/cgi-bin/action.sh?jobid=$job_id&action=kill-job" | mail -s "Job Keep alive or kill" vidyasagar@xyz.com fi done < qstatfile CGI script #!/bin/bash echo "Content-type: text/html" echo "" JOBID=`echo "$QUERY_STRING" | sed -n 's/^.*jobid=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` ACTION=`echo "$QUERY_STRING" | sed -n 's/^.*action=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` echo "<html><head><title>What You Said</title></head>" echo "<body>Here's what you said:" echo "You entered $JOBID for job ID and wanted the action to be $ACTION." echo "</body>" echo "</html>" Now when user select kill option i want to send qdel $job_id signal through script where to put this command qdel $job_id |
Sounds like you want a batch service, there are several to choose from
PBS, Loadleveler... https://en.wikipedia.org/wiki/Job_scheduler |
All times are GMT -5. The time now is 10:41 PM. |