need to have a cronjob which will execute certain scripts every hr


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to have a cronjob which will execute certain scripts every hr
# 1  
Old 03-04-2009
scripting to update oracle db periodically

Hi

My question needs two answers

how to write scripts to update a table in oracle db based on the result of the number of record counts

for example
i need to execute the following script every hour
Code:
awk '{sum[$4]++;}END{for(i in sum) {print i, sum[i]}}' filename

here everyhour the filename will be changing...like 200903042106 at 22:05 hrs and 200903042206 at 23:05hrs

(year month day hr min format)

the output will be varying for each execution
for e.g output for 200903042106 will be
Code:
RTMS 100
BSNLSERVICE1 324

and output for 200903042206 will be

Code:
RTMS 50
BSNLSERVICE1 264
CAE 25
PFS 98
DATING 49

I WILL BE HAVING A TABLE WITH ALL POSSIBLE COULMNS (WHICH MAY COME IN THE OUTPUT OF THE SCRIPT LIKE...RTMS)

the think is i should be able to read what is first value (RTMS or BSNLSERVICE1 or CAE...etc) and then insert in to the db, the count corresponding to that column leaving other columns with null values or blank...along with the timestamp in timestamp column of the time table which i can make use for querying purpose...like between dates or interval...etc


DB should reflect like the following:
Code:
TIMESTAMP | RTMS | BSNLSERVICE1 | CAE | PFS | DATING |
200903042106 | 100 | 324 | 0 | 0 | 0 |
200903042206 | 50 | 264 | 25 | 98 | 49 |

how it can be achieved?

then 2nd question
about creating the cronjob dynamically with varing file names as told already

with thanks
Aemunathan

Last edited by aemunathan; 03-04-2009 at 10:16 PM..
# 2  
Old 03-05-2009
this would give you current date and time:
Code:
date '+%G%m%d%H%M'

similarly, you can prepare the required timestamp

to know about cron and how to setup a cron job see this
# 3  
Old 03-07-2009
Hi

Am trying to connect to oracle db like ....

created one script file like connect.sh which contains
Code:
#!/bin/bash
cd /u01/app/oracle/product/9.2.0/bin/
sqlplus -l xxx/xxxx@yyy <<EOF
select distinct application_code from event_service;
exit
eof

if i execute this by ./connect.sh it works fine

but when i added this in to the crontab...it throws some error

crontab file entry
Code:
15 * * * * /aemu/connect.sh > /aemu/logs.txt 2>&1

it is not storing the output to the file name logs.txt as well

under /var/mail am seeing some mails related to this....

Code:
Date: Sat, 7 Mar 2009 22:45:00 +0530 (IST)
From: Super-User <root@ss.com>
Message-Id: <200903071715.n27HF0Yv002256@ss.com>
To: root@ss.com
Subject: Output from "cron" command
Content-Type: text
Content-Length: 141

Your "cron" job on rtmssrv1
/aemu/connect.sh > /aemu/logs.txt

produced the following output:

/aemu/connect.sh: sqlplus: command not found

can anyone help me out to find the errors
# 4  
Old 03-11-2009
hi

i have tested connecting to db through script...i was missing the path from where i can run sqlplus command ....

now connection to db is ok...

how to update the table with the two column values i may receive from the command

Code:
awk '{sum[$4]++;}END{for(i in sum) {print i, sum[i]}}' filename

how to fetch those values and add in table along with date info.


Please help me out!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Execute Ubuntu 14.04 cronjob as non-root

I have created a cronjob that successfully executes and among other thing runs aria2c to download several files and save them to a folder. However, since it executes as sudo, the downloaded folder is saved with those permissions. Is there a way to execute the cronjob so that the downloaded folder... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. AIX

Need ./ to execute scripts

Hi, I am really sorry for this question but still i am confused. I have shell script called sample.sh I can execute only with the combination of ./sample.sh Is ./ really necessary ? Is it something related with $HOME or $PATH variable. Why and How can i resolve this case ? ... (2 Replies)
Discussion started by: Nandy
2 Replies

3. Shell Programming and Scripting

Unable to execute glance from cronjob

Hi I am writing a script to get the CPU and memory utilization periodically from glance command. Wrote a script which consists of below two lines Script name : Utilization.sh #!/bin/sh glance -iterations 1 | sed -n '/Util/p/'| awk '!/Disk/'| awk '!/Swap/' >> file.txt I am able to run the... (5 Replies)
Discussion started by: Shravani
5 Replies

4. Shell Programming and Scripting

Cronjob to be execute today at 9pm

HI Folks, Sorry for this basic confusion but please help me. i want to execute one script at 9pm today. i want make this as schedule so it can execute automatically. So am doing like this. 21 10 24 4 <here what can i keep) /tmp/stemp/testcron.ksh Can you please help on this? ... (6 Replies)
Discussion started by: coolboy98699
6 Replies

5. Shell Programming and Scripting

expect telnet script execute by cronjob

hi, please help, keep getting this bolded error and look it up and people say its your environment variable though i tried to set it manually in expect..it run fine if i run it manually but once i run it by cronjob it error below..i tried to comment out ip/login info with *.. logfile:: START... (0 Replies)
Discussion started by: cssanangeles
0 Replies

6. Shell Programming and Scripting

Execute Shell Script from CRONJOB

Hi Users, I am Newbie to linux and cron. I have a requirement to run a job at 8 AM every Sunday. I am using RHEL 5. Based on the hints through google search I created crontab and added entry to call the shell script which will in turn login to Oracle user and execute a pl/sql block. ... (1 Reply)
Discussion started by: reachravi70
1 Replies

7. Shell Programming and Scripting

How to execute cronjob running in a different machine?

Hi, I am developing 1 script in which I need to execute one cron job running in different server and my script is in different server. so can any one help me to execute the cronjob set in different server. Thanks in advance. (1 Reply)
Discussion started by: mridul10_crj
1 Replies

8. Shell Programming and Scripting

Check a condition in cronjob to execute a sh file

Hi, I need to execute a crontab based on a condition where one SH file should be executed only based on the output of a file in a folder. I have written the following cron job which is not working. 00 01 * * * read a < /px/batch/reslut.txt && && sh /px/batch/check.sh where my... (2 Replies)
Discussion started by: shanth_chandra
2 Replies

9. Shell Programming and Scripting

Running scripts through cronjob.

Hello everybody, I'm trying to run a shell script in crontab file. But anyhow it's not getting executed. Following is the command that I've used in crontab. 30 07 * * * . ./.cronprofile;/om/reports/reportscripts/jitu/prod/prd_pre_to_post.sh 35 11 * * * .... (3 Replies)
Discussion started by: jitu.jk
3 Replies

10. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies
Login or Register to Ask a Question