How to automate a command to run in crontab?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to automate a command to run in crontab?
# 1  
Old 03-19-2013
How to automate a command to run in crontab?

Hello all
I am very new to scripting and would like your help to accomplish this task.

I have to cd the adump directory every single day and manually run the following command when I receive an alert saying that audit files exceeded 10.000 files limit.

cd /opt/app/dcweblog/oracle/admin/PW4ARBY/adump
find . -name '*.aud*' | xargs rm

What I need is the step to implement to automate to run twice everyday
####################
vi maxrm_audfile.ksh
#!/bin/bash
find . -name '*.aud*' | xargs rm

####################

thanks in advance
# 2  
Old 03-19-2013
You should do

find /absolute/path/to/folder/, not find . in cron since it won't actually be logging in as you when run from cron.


Perhaps this:
Code:
0 0,12 * * * find /path/to/home -name '*.aud*' | xargs rm

You may need to specify absolute paths to find and xargs and rm, too.
# 3  
Old 03-19-2013
Corona688
Thank you for the quick response.
To illustrate what you recommend i should is the following:
####################
vi maxrm_audfile.ksh
#!/bin/bash
0 0,12 * * * find /opt/app/dcweblog/oracle/admin/PW4ARBY/adump -name '*.aud*' | xargs rm.
ls * | wc -l

What if I want the word count after the above command was executed? Can I include
ls * | wc -l as the above?
####################
# 4  
Old 03-19-2013
If it's running automatically, echoing a number likely won't go anywhere. It's possible to arrange it being sent to an email but this depends on the configuration of your server.

And no, you don't put that line in a bash script, you put it in your crontab, which you edit with crontab -e.
# 5  
Old 03-19-2013
Thanks for your responseSmilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can't get my crontab to run

I'm trying to get a crontab to run, every Friday at 11am and the problem is that it isn't running at all. 0 11 * * 6 /Users/martinb/Documents/SYSADMIN/Regular-Scripts/Info-And-Backups.sh Here's a link to a screenshot of my script (I've censored my email address). Screen Shot 2017 11 03... (3 Replies)
Discussion started by: $shell_Learner
3 Replies

2. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

3. Shell Programming and Scripting

Why my git command has no output in crontab but works well run this script manually?

cat /home/lyang001/update.sh #!/bin/sh #shopt -s expand_aliases HOME_DIR=/home/lyang001/updates UPDATE_MAIL=${HOME_DIR}/updates.mail rm $UPDATE_MAIL -rf cd $HOME_DIR/wr-kernel git log --no-merges --since="20 day ago" --name-status --pretty=format:"%an %h %s %cd" origin/WRLINUX_5_0_1_HEAD >>... (2 Replies)
Discussion started by: yanglei_fage
2 Replies

4. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

5. HP-UX

Crontab do not run on PM hours

Hi All I have a problem, I wonder if you can help me sort it out: I have the following entry in the cron: 00 1,13 * * * /home/report/opn_amt_gestores_credito.ksh > opn_amt_gestores_credito.log But the entry only runs at 01:07 I have stopped the cron deamon, and started, but it still... (39 Replies)
Discussion started by: fretagi
39 Replies

6. Shell Programming and Scripting

Different output when run from crontab

Hi, I have a script which checks to see if an app is running and will restart it if it is not. For some reason when I run it from the crontab it always says it is not running. The script is as follows: - #!/bin/sh # # The following script will look for the PID of SickBeard and output... (15 Replies)
Discussion started by: simpic
15 Replies

7. Solaris

crontab to run every 20 second

Hi experts, I want to set the crontab for my script which will run every 20 seconds I think below could be the possible one- */3 * * * * /export/home/username/scripts/runing.sh As my system(SOLARIS 9) is live- i am confused to implement before make sure !!! I need... (4 Replies)
Discussion started by: thepurple
4 Replies

8. UNIX for Advanced & Expert Users

CRONTAB does not run since reboot

Hi, we reboot our Linux server yesterday and since then (specialy last night) no job from crontab has run. Any idea ? What should I look for to investigate? Many thanks. (5 Replies)
Discussion started by: big123456
5 Replies

9. HP-UX

Run crontab every 6 days

Hi all, I need to run a shell script every 6 days using crontab. I've been searching a bit and found the following syntax for this: * * */6 * * /apps/temp/maxx.sh > /apps/temp/maxx.log 2>&1 respectively * * 0/6 * * /apps/temp/maxx.sh > /apps/temp/maxx.log 2>& Unfortunately when trying to... (8 Replies)
Discussion started by: Endo
8 Replies

10. UNIX for Advanced & Expert Users

crontab couldn't run through, help

I have created two scripts to call SQL scripts to do some work. The scripts was successfully executed many times by manual. When I scheduled two scripts in crontab, I gave all necessary parameters. It could start, but couldn't run through. The log file didn't give enough error info. Anyone can help... (10 Replies)
Discussion started by: duke0001
10 Replies
Login or Register to Ask a Question