Sponsored Content
Top Forums Shell Programming and Scripting Example of running script with time limits? Post 302833853 by newbie_01 on Thursday 18th of July 2013 02:39:00 AM
Old 07-18-2013
Example of running script with time limits?

Hi,

I want to write a script that does some sort of health check on the database. It will query the database for information, some query takes long and some are quick.

For example, inside the script I will do something as below:

Code:
#!/bin/ksh

run_query_01 &
run_query_02 &
run_query_03 &
run_query_04 &

run_query_check_output

...
...

Reason why I want the run_query to run in the background/& is so that the script finishes quickly. I need some guidance though on how do I implement run_query_check_output.

At the moment, I am thinking each run_query in the background will create a .end file before it exits and run_query_check_output will check if this file exists or not, if it exists then the query has finished, if not, check again and wait until it find a .end file.for each run

The other thing I want to be able to check though is to put a time limit of the run of each run_query that I ran in the background. For example, if one runs for more than 15 minutes, I want it to be killed or maybe it can kill itself. Is this possible to implement? Or maybe I should spawn another script that runs in the background too that checks how long each run_query script in the background has been running? How do I check how long each background script has been running so far though? Smilie

Does anyone has an example of what I am wanting to do? Please advise.

Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

to compare latest logfile with the current running time of the script

how can i compare the latest log file with the current time.. consider i am running a script "a.sh" at 09:00 ( function of the script a.sh is to update the database ) this script is going to create logfile if the script is sucess in case of failure it is not going to create logfile.. ... (0 Replies)
Discussion started by: mail2sant
0 Replies

2. Shell Programming and Scripting

display time required to complete running script

hi is there any way i can display a countdown time needed to run a script? like load a counter at the beginning of the script with the estimated time and display the counter decrementing till it finishes running the script? (3 Replies)
Discussion started by: npatwardhan
3 Replies

3. Shell Programming and Scripting

Running batches of files at a time from a script

Hi I have a script that performs a process on a file. I want to know how to include a function to run a batch of files? Here is my script #!/bin/bash #---------------------------------------------------------------------------------------------------------------------- #This... (2 Replies)
Discussion started by: ladyAnne
2 Replies

4. Emergency UNIX and Linux Support

Help to optimize script running time

Dear Forum experts I have the below script which I made to run under bash shell, it runs perfectly for low records number, let us say like 100000. when I put all records (3,000,000), it's takes hours can you please suggest anything to optimize or to run in different way :-| {OFS="|";... (6 Replies)
Discussion started by: yahyaaa
6 Replies

5. Shell Programming and Scripting

Help in running a script after a particular time

Unix Gurus, I have a requirement where the shell script needs to do specific tasks after certain period of time. Daily we receive few files in a particular folder. The script does the file renaming, pass parameters to run some web services and pushes to remote FTP location. But my... (3 Replies)
Discussion started by: shankar1dada
3 Replies

6. Shell Programming and Scripting

How to know the exact running time of script!

Hi All, newbie here, I'm just wondering how can i know the exact running time of my script? Please advise, THanks, (1 Reply)
Discussion started by: nikki1200
1 Replies

7. Shell Programming and Scripting

Find the script running time and subtract from sleeptime

HI Guys, I want to find out the script running time and subtract from sleeptime. My Script Below Give me error :- #!/usr/bin/ksh timeout=100 start=$SECONDS sleep 20 end=$SECONDS echo "Time: $((end - start)) " ScTime = $((end - start)) (1 Reply)
Discussion started by: asavaliya
1 Replies

8. Shell Programming and Scripting

Setting time for running of the script

Dear all, I wonder if it is possible that we can run the script from time to time..I meant, it should repeat the sourcing of the script by itself? In my case, I need to source this script manually from time to time, like once in every 10 minutes. emily, (2 Replies)
Discussion started by: emily
2 Replies

9. UNIX for Dummies Questions & Answers

Soft and hard limits for nproc value in /etc/security/limits.conf file (Linux )

OS version : RHEL 6.5 Below is an excerpt from /etc/security/limits.conf file for OS User named appusr in our server appusr soft nproc 2047 appusr hard nproc 16384 What will happen if appusr has already spawned 2047 processes and wants to spawn 2048th process ? I just want to know... (3 Replies)
Discussion started by: kraljic
3 Replies

10. Shell Programming and Scripting

Killing the process if running for long time in script

I am running a script which will read the data from fail line by line and call the Java program by providing the arguments from the each line. The Java code is working fast for few records and for some records its getting hanged not providing response for morethan one hour. Currently am... (4 Replies)
Discussion started by: dineshaila
4 Replies
JABBER-QUERYBOT(1p)					User Contributed Perl Documentation				       JABBER-QUERYBOT(1p)

NAME
jabber-querybot - a modular perl jabber bot DESCRIPTION
jabber-querybot connects a jabber account and wait for messages. If a message comes in, it forward it to your self programmend modul. The return string of your module, jabber-querybot send it back to the jabber sender. It is designed to be re-usable and to make it easy to write small Jabber bots that do one thing and do it well. A simple concept with a lot of examples and experiences are implemented. 1. Create a jabber account on a jabber-server around 2. Create a bot application: cd examples cp Querymodule.pm /etc/jabber-querybot/Mybot.pm cd /etc/jabber-querybot ln -s Mybot.pm Querymodule.pm Modify login parameters to your jabber-bot-account vim Mybot.pm our $hostname = "swissjabber.ch"; our $user = ""; our $password = ""; our $ident = "Testbot"; our $bot_admin = "@swissjabber.ch"; our $port = "5222"; our $timeout = "5"; our $service_name = "$user@$hostname"; our $bot_description = "Bot help title Bot description"; For each jabber message, jabber-querybot will execute sub run_query, that you can write here your application. You can control how your jabber response will be: o error = error message stanza o presence = error as presence stanza o ignore = ignore message OPTIONS
jabber-querybot has a lot of variables which you can easy modify for what you need: querystatus $querystatus = [ 0 | 1 ] o 0 = Bot will not proceed any incoming jabber messages. o 1 = Bot will proceed incoming messages. penalty_status If the bot has too much workload, it goes to penalty status and wait some time until his status change back to normal. $timer_reconnect_default = 21600 Every 21600 seconds (6 hours) the bot will shutdown automatically, wait 10 seconds and starting up again. $timer_auto_query = 0 If you set in your module this variable to 60, the bot will every 60 seconds call the function run_auto_query() which you may use for several things. System load If your systems load is >=6, this bot will shutdown the jabber connection and check every 10 seconds systems load. If load <=2, bot will start over. EXAMPLES
/usr/share/doc/jabber-querybot/examples/Testbot.pm FILES
/etc/jabber-querybot/Querymodule.pm /usr/bin/jabber-querybot RESOURCES
http://github.com/micressor/jabber-querybot/ METHODS
InMessage() An incoming jabber message to the bot will hook this function. o Read parameters of incoming stanza o Decode utf8 string o increment timer overload and do not process message if bot is overloaded. o Ignore message if it is from myself o Be sure, that it is not a message from another transport o Check any systemcommands for the bot o If the bot has sleeping status, change it to work o We process only normal text or chat type jabber messages o And now we give the real text string which was incoming to the bot via run_query(). o If run_query() say us 'ignore` we do a log entry and do not answer via jabber to the user. o If run_query() says 'error` we send a jabber error stanza wiht the status message from run_query() back to the user. o If there was no error, we update the statistic vars and send the answer from run_query() back to the jabber user. connect_server() This function connects to the jabber server with the given credentials from Querymodule.pm. Set the call back functions. This functions will be executed if a message of the types <message/> <iq/> or <presence/> are incoming. Stop() Shutdown jabber connection and exit main program disconnect_server() Only disconnect from the jabber-server. reconnect_server() Reconnect and create a log entry. InIQ() We do not proceed any iq (information query), this is only for statisic. InPresence() o Increment timer overload o Do not process message if we are overloaded penalty_handler(). We have a problem in Net::Jabber. An incoming message with a ` in resource blocks the bot. We will hotfix that for the moment. A subscription type `subscribe` is incoming. Send `subscribed` tho the user and say hello ;) o Send presence to user o Remove subscription if a user remove this bot from his roster sendPresence() Send presence information to user systemcommands() o If user type '!help` send a help instruction to the user o Send statistic information to the user if he types '!status` o Is it a bot command? o Is the bot command from the bot admin? If not, send "not allowed" o '!shutdown` will shutdown your bot via jabber invoke. o '!query off` turn off queries o '!query on` turn on queries get_barejid() Remove resource id from a jabber id. calcualte_stats() Calculate message statistics jabber_set_presence() Set new presence if we have another presence status or we have set the force flag (for transport presence). jabber_send_message() This function send all jabber messages which are outgoing from the jabber-querybot. set_wakeup_mode() Set jabber presence via jabber_set_presence() penalty_handler() This function checks if the bot is overloaded with incoming mesages and reject if it is. Two times that's ok so 2:1 because while in main. Bot admin got everytime an answer. jabber_add_footer() Add footer to the processed message. calcualte_elapsed_time() Calculate elapsed worktime for a query sendError() sendError($message, $from, $to, 404, "text"); system_load_check() o Calculate system load o If load is too high shutdown bot. o If load is ok, starting up bot connect_bot() Connect bot and initialize all timers. check_before_start() Check configuration variables in Querybotmodule.pm and give answer if anything does not match or is missing. COPYRIGHT AND LICENSE
Copyright (C) 2009-2012 Marco Balmer <marco@balmer.name> The Debian packaging is licensed under the GPL, see `/usr/share/common-licenses/GPL-3'. perl v5.14.2 2012-02-03 JABBER-QUERYBOT(1p)
All times are GMT -4. The time now is 06:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy