CRON JOB to be scheduled daily to remove log files

Can Any one help me on how to create a script in SUSE Linux to delete files in specific folder and then schedule it using cron?

I am newbie in SUSE and Linux world.

Thank you

On 21/06/16 11:44, mmoutaweh wrote:
[color=blue]

Can Any one help me on how to create a script in SUSE Linux to delete
files in specific folder and then schedule it using cron?

I am newbie in SUSE and Linux world.[/color]

Since you’ve posted in a forum for SUSE Linux Enterprise Desktop (SLED)
can I ask if you are using SLED or perhaps SLES?

With SLEx the simplest option would be drop a file in /etc/cron.daily/
which contains:

–begin–
#!/bin/sh

rm /path/to/files/filename.ext

exit 0
—end—

Obviously you want to make sure that this file is owned by the root user
and group and no other users have write permission.

This file will then be run along with the other daily jobs.

If you want to ensure these jobs always happen at a certain time each
day (rather than tied to time machine last restarted) you can set
DAILY_TIME in /etc/sysconfig/cron.

HTH.

Simon
SUSE Knowledge Partner


If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below. Thanks.

I am using SLES (Server version).

I created the following file in /etc/cron.daily/

–begin–
#!/bin/sh

rm /usr/sap/NDB/HDB00/backup/log/.

exit 0
—end—

and set DAILY_TIME=“12:30” to run the script at 12:30 pm but nothing happened

So I added the following command in crontab

40 12 * * * root rm -f /var/spool/cron/lastrun/cron.daily

to run it at 12:40 pm but also nothing happened.

Is there anything missing in my steps?

Thanks,
Marwa

On 22/06/16 09:44, mmoutaweh wrote:
[color=blue]

I am using SLES (Server version).[/color]

In which you should have posted to the SLES Forums @
https://forums.suse.com/forumdisplay.php?8-SUSE-Linux-Enterprise-Server
but we’re here now and it could be relevant for SLED users so …
[color=blue]

I created the following file in /etc/cron.daily/

–begin–
#!/bin/sh

rm /usr/sap/NDB/HDB00/backup/log/.

exit 0
—end—

and set DAILY_TIME=“12:30” to run the script at 12:30 pm but nothing
happened[/color]

I think you need to restart cron for the change of DAILY_TIME to take
effect - since I don’t know the SLES version “rccron restart” should work.

If I recall correctly it takes 2 days for a new daily job to first run -
see TID 3842311[1].
[color=blue]

So I added the following command in crontab

40 12 * * * root rm -f /var/spool/cron/lastrun/cron.daily

to run it at 12:40 pm but also nothing happened.[/color]

Just as well. Why set cron to delete the
/var/spool/cron/lastrun/cron.daily file at 12:40 every day?

You could have added “> /path/to/logfile 2>&1” to log output to
/path/to/logfile.
[color=blue]

Is there anything missing in my steps?[/color]

I don’t think so, you just need to be patient (and remove that cron
command from the crontab file).

HTH.

[1] https://www.suse.com/support/kb/doc?id=3842311

Simon
SUSE Knowledge Partner


If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below. Thanks.

Thank you Simon.
I have done what you suggested and will be waiting. However, I need to do that periodically after 1 hour due to the large size of logs that is increasing quickly. I will re-post this on the SLES forum.

Thanks for your help.

Regards,
Marwa Moutaweh