I have few catalogues in my linux directory , the files name is logs-YYMMDD
/logs-140617
/logs-140616
/logs-140615
Can somebody tell me how to write bash script to repeat every day and pack file by date -1 day (today bash script would create archive of logs-140616 and delete unpacked file ?
Thanks for answers
use logrotate for that purpose, that's what it is for.
For periodically executing stuff, a cron job is the way to do that.
logrotate already gets executed by cron, on a daily base. Therefore, when using logrotate, there would be not need to fiddle with the daily-execution aspect of your problem.
Related
I want to set a crontab file in my project repo so that it is tracked and easy to manage. So, I'd prefer if I could add cron jobs in a file in my project e.g. /home/user1/project/.crontab instead of /var/spool/cron/crontab or /etc/crontab. Is there any way to do this?
Operating system would be ubuntu.
There is no way to make cron use a different file. The daemon's files are stored in a location owned by the daemon itself which generally cannot be overridden.
But of course, you can always make sure the file that cron reads is identical to yours.
crontab < /home/user1/project/.crontab
will replace any cron schedule for the current user with the contents of the input file.
Each morning, a config file is fed with a list of hours. Hours in the json file are different each days.
I would like a python script to be executed for each hour of the configuration file. What is the best way to do this?
Do I have to do a loop while? What is the best practice?
You can set up a cronjob that reads the config file and executes the python scripts every morning.
I would recommend this video.
basically, you can schedule a python script daily that will execuetes automatically.
I have a batch that integrates an xml file time to time but could happens daily. After it integrates it puts in a folder like /archives/YYMMDD(current day). The problem is if the same file is integrated twice. So I need a script what verifys the file (with diff command its possible but risky to make a bottleneck) but the problem is I can't find to resolve how to make to give the second files location.
P.S. I can't install on the server anything.
Thanks in advance.
I'm not an advanced user of Linux, but I'm looking for some simple script in bash which will be working in cron or any other way and in 5-10 minutes period time will be looking for new files, after new directory/files are already uploaded to the directory script will move new directory with files to other location.
I found inotify which can be a great solution for this, but the issue is how to go with it.
I've been using inotifywait to recognize that some filesystem change ocurred in certain path.
Take a look at:
http://linux.die.net/man/1/inotifywait
You can specify on what changes you are interested (delete, create, modify, etc.) and whether the script should output it or simply exit after change.
I've been using this tool in a way that my script was starting inotifywait and when it exists, do some action and restart inotifywait again.
Hope this helps.
Martin
This is probably stupidly obvious beginner question, but somehow I can't find the answer.
On my debian box, I have a script in /etc/cron.d. It executes every once in a while, but I can't find the schedule or initiator. I've tried looking at all users cron tabs, as described here, but no user has a script that runs the cron.d. I've looked at /etc/crontab, which holds the scripts for cron.daily, monthly and hourly, but not cron.d.
Where is this schedule held?
From the output of man cron,
Support for /etc/cron.d is included in the cron daemon itself,
which handles this location as the system-wide crontab spool. This
directory can contain any file defining tasks following the
format used in /etc/crontab, i.e. unlike the user cron spool, these
files must provide the username to run the task as in the task
definition.
This implies that the file inside /etc/cron.d should not be a script, but rather a configuration file that looks similar to /etc/crontab. It will carry its own scheduling information, the same way that /etc/crontab does. In particular, the format should look like:
# m h dom mon dow user command