Can You Load Only Part of a Crontab File?
What I would like to know is it possible to modify a lengthy crontab file so that cron only loads the first “X” number of lines? I am looking for something that would be similar to adding an “exit” line in the middle of a bash script
I know I can comment out the active lines with “#” and use “##” to mark those lines that now have a single “#” because the lines are not currently being used and are there for historical purposes, but it would nice if there was an easier way of preventing a whole block of lines below a certain line from being active. |
I've never tried it, but I believe the short answer is "No."
|
Quote:
|
sed ?
|
Quote:
|
Quote:
Edit: I just discovered it not only loaded the temporary file into memory but it created a new shortened crontab file as well. That is not what I wanted. Luckily I have a backup and I will rework the script to use a renamed crontab file so it will not get overwritten. |
Quote:
Would you be willing to post the script, being sure to surround it with "code" tags, which become available when you click the "Go Advanced" button at the bottom of the "compose post" window? |
I normally don't but I will put on my fireproof suit this time :)
Code:
sed -n 1,$1p /root/tmp/workfile > /root/tmp/temp.root I added the third line after my post so I could check to see what actually was loaded. I use ctl-c in pico to determine how many lines I want to pass to the script. |
An alternative to take the first x lines to a new file?
Code:
head -x /root/tmp/workfile > /root/tmp/temp.root Should work from the command line, or as in your script with $1 instead of a hard-code for x (or have I misunderstood?) |
You didn’t misunderstand and that is a good thought. You could even pass two line number locations as arguments and pipe the first results to “tail -y” based on the difference between the arguments to only use y number of lines from the middle. I was focused on finding a solution using sed because that was what was suggested. There are probably many different ways of accomplishing the same thing.
In truth, as frankbell indicated above, there is no way to do it as nicely as the “exit” in the middle of bash script. If I had realized that the actual crontab file is not only the input but also a reflection of what cron has loaded, I would have known not to even ask the question. At least this was a learning experience. |
Quote:
Note, however, that crontab doesn't necessarily contain everything that cron is running. My server has directories Code:
/etc/cron.d |
Just a FYI, crontab only maintains crontab files for users which are usually saved to /var/spool/cron/crontabs.
The files in the /etc directory are typically system cron jobs. |
Quote:
|
Actually root has its own cron files that can be created etc. via crontab.
System wide cron jobs can be run by any user but typically as root. Some system cron jobs are logrotate and updatedb which is the database used by the locate command. |
All times are GMT -5. The time now is 06:59 AM. |