I'm trying to write shell script that when invoke, has 2 arguements, or 1.
If there's one arguement, then that's the process name. If there's 2, then one is the timeout.
USAGE: Assign1.sh <process> <timeout>
If no timeout was set, then the default timeout is 15 minutes.
So after it read the process and time out, then it check how long the process has been running, then check with the current time to see if it's been 15 minutes. If it has, then it kill the process, if it hasn't, then it exit.
Here's my script:
No idea why it's not working! :-(
Any help would be greatly appreciated
I'm trying to write shell script that when invoke, has 2 arguements, or 1.
If there's one arguement, then that's the process name. If there's 2, then one is the timeout.
USAGE: Assign1.sh <process> <timeout>
If no timeout was set, then the default timeout is 15 minutes.
So after it read the process and time out, then it check how long the process has been running, then check with the current time to see if it's been 15 minutes. If it has, then it kill the process, if it hasn't, then it exit.
Here's my script:
No idea why it's not working! :-(
Any help would be greatly appreciated
STIME=`echo $STIME | awk -F" " '{print $2}'` # what is the purpose of this??
STIME=`$STIME | awk -F: '{print $1*60+$2}'` # you have to put as echo $STIME before piping it to awk..
I fixed the echo $STIME thing.
The second one was to pick the second time. I noticed sometime it output two or three times... like there was two or three process of the same name running. I chose the second one because it always seem to have a lower time, meaning it's been running the longest.
Here's what I get when I run "sh -x assign1.sh bash 20"
It looks like my current_time became negative somehow???
Beware of fuzzy matching with grep. In this line the parameter $1 could match any like number in the "ps -fu $USERNAME" output. For example the parent PID of a subprocess or say some part of the cpu usage. In this form of grep it would find "12" in "61234" or in "12:46".
Tip: "ps -fp${process_id}" would give you the status of that one process.
Sorry to be unhelpful but I believe that this script design is fundamentally flawed because "ps" changes the date format as processes get older and this changes the positional parameters presented to awk.
Login as root have a look at "ps -ef" on a system which has been up for more than 24 hours.
Last edited by methyl; 04-04-2009 at 10:09 PM..
Reason: tags displaced
the "sh -x" REALLY HELPS, it's like a debug almost? run one line at a time and shows me the output and everything. Very neat to know.
I realized that the STIME and CURRENT_TIME were both saved as strings, so they cant be compute... when they do, the output was null, so it never worked.
I changed them to int with typeset -i and it worked. Woo!
Probably not very good coding... but it works... I'll figure out a different approach later.
the "sh -x" REALLY HELPS, it's like a debug almost? run one line at a time and shows me the output and everything. Very neat to know.
I realized that the STIME and CURRENT_TIME were both saved as strings, so they cant be compute... when they do, the output was null, so it never worked.
I changed them to int with typeset -i and it worked. Woo!
Probably not very good coding... but it works... I'll figure out a different approach later.
good you understand the imp of "sh -x"
way to go buddy!!!
regards,
vidya
Hello all,
I am trying to spool a SQL query output file from back-end to desktop in a certain path but it didn't work,the query writes the output in a file in the same directory at the back-end.
note : i use the same query in sql developper and file was created in the desired path fine
code... (1 Reply)
I have several line in a text file. for example
I like apple;
I like apple
I like orange;
Output: I like apple
I try to useif grep -q "!\;$"; then (Not work)
Please use CODE tags when displaying sample input, sample output, and code segments (as required by forum rules). (1 Reply)
Hi friends ,
I want to know how does a shell script recognize the end of a line? . i have hunddres of proccedure to test where i want to ingnore the comments which starts with "--" .. it can start from the middle of the lines also. for example::
select * from table1; -- getting... (5 Replies)
Hello,
I need to make shell script menu for my end users. There is like 100 scripts in system, and they need to run that scripts true one main script with user friendly menu.
Example, when user will run main menu script, it will get something like this on his screen:... (1 Reply)
Hello,
I need to make shell script menu for my end users. There is like 100 scripts in system, and they need to run that scripts true one main script with user friendly menu.
Example, when user will run main menu script, it will get something like this on his screen:... (3 Replies)
Hi, I am looking for a solution for the following problem:
Im Using tcpdump within a shellskript started in a subshell by using brackets: ( /usr/sbin/tcpdump -i ... -c 1 )
- I want the outout of tcpdump saved in a variable
- Than tcpdump-Process in the Subshell should be killed
- and I... (6 Replies)
Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it
This is how we execute the script (and this is the requirement) ... (2 Replies)
Hello.
I have a file (old.txt) that I need to copy into another file (new.txt).
Each line on old.txt ends with CR/LF but the position of CR/LF varies from one record to another.
I need to copy each line of record to new.txt and move CR/LF in pos 165.
Can I use awk to achieve this? How?... (8 Replies)
i was wondering how to add a notes section for the user to enter in a shell script, as my shell script is a menu based on configurations of hardware and software
help is appreciated (4 Replies)
My shell script was working ok with K shell.
But all of sudden, it started acting crazy.
it keeps saying this:
syntax error at line 70 : `"' unmatched
I don't even have 70 lines in my file
or this :
syntax error at line 69: `end of file' unexpected
Can this file got... (5 Replies)