Vim is the default editor of crontab.
So, I'm gonna use it here.
Create your script file - any editor, but using vim:
vim clean_wtmpx.sh
Add your command line - type 'i' to get into the insert mode and then these commands:
#!/bin/sh
cat /dev/null > /var/adm/wtmpx
To save and close - hit "esc" to get out the insert mode and then type:
:x
The first line is used to indicate a shell script on bash. It's optional.
Set permissions on the new file created:
chmod 775 clean_wtmpx.sh
Test you command before, executing it. Type on prompt:
./clean_wtmpx.sh
Open the crontab on edit mode:
crontab -e
Add this line:
20 22 * * * dir_path/clean_wtmpx.sh 2>> dir_path/crontab.lob
To save and exit the crontab:
esc
:x
Explaining the crontab's command line:
dir_path is your path the "clean_wtmpx.sh" file.
Everyday at 10:20 PM the script "dir_path/clean_wtmpx.sh" will run.
If just in the case of some output is generated (for instance error messages) is saved on "crontab.log" file.
Certainly, this is not the case of your command, so you can ignore the log file, setting like this:
20 22 * * * dir_path/clean_wtmpx.sh
Extra - short summary:
To list what you have on crontab, type:
contrab -l
The crontab command line is divided in space delimited fields.
The first 5 fields is related about time settting followed by a command field, using this format:
minutes hour day_of_month month day_of_week command
Tip:
Always perform a crontab's test, creating a fake line to start your command in the next one or two minutes in order to check it.
No comments:
Post a Comment