LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-13-2015, 09:39 AM   #1
sagar666
Member
 
Registered: Feb 2013
Posts: 212

Rep: Reputation: Disabled
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

Last edited by sagar666; 06-13-2015 at 09:44 AM.
 
Old 06-14-2015, 02:25 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
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?
 
Old 06-14-2015, 03:33 AM   #3
yo8rxp
Member
 
Registered: Jul 2009
Location: Romania
Distribution: Ubuntu 10.04 Gnome 2
Posts: 102

Rep: Reputation: 31
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
 
Old 06-14-2015, 06:23 AM   #4
sagar666
Member
 
Registered: Feb 2013
Posts: 212

Original Poster
Rep: Reputation: Disabled
#!/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
 
Old 06-14-2015, 08:58 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Sounds like you want a batch service, there are several to choose from
PBS, Loadleveler...

https://en.wikipedia.org/wiki/Job_scheduler
 
  


Reply

Tags
cgi, html, linux, programing, scripting



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
form data as $1, shell script & cgi haiders Programming 3 07-13-2011 06:38 PM
[SOLVED] HTML Form that sends data entered to a bash script as variables simplified Programming 2 12-01-2009 03:35 PM
shell script works form command line but not form crontab saifee General 1 10-14-2004 10:27 AM
Simple php script with html form not working. sinsoush Programming 4 04-01-2004 08:02 PM
shell script form submit precioso77 Linux - General 2 05-18-2003 11:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:31 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
Open Source Consulting | Domain Registration