1

I'm using cat /var/spool/cron/* to view all cron jobs created by all cpanel users.

Is it possible to edit its output just like editing via nano and hit save?

1 Answer 1

0

If are you trying to do collision detection and prevention (as indicated in another question you've asked), then a simple way to accomplish what you ask would be

cat /var/spool/cron/* >/tmp/cat.out; $EDITOR /tmp/cat.out

which would concatenate all the multiple users' crontabs into a single file, save, and edit it. But I don't see much utility to this. Much more useful would be

ls /var/spool/cron/* | xargs -i $EDITOR {}

which would edit each users' crontab in sequence, save, and then open the next. It would be incumbent upon you (as root) to notice and correct the conflicts between each file.

A further refinement would be to create an annotated version of the first approach to identify the issues, and then to go back and edit the particular user crontabs individually for fixes.

for I in /var/spool/cron/*; \
do awk '!/^#/&&!/^[^[:blank:]]*=/{printf "%s:\t%s\n", F, $0}' F=$I $I; \
done |sort -k2 | less

will list all the content of all the crontab files except for comments and environment variable assignments, prefixed each with the particular contributing crontab file name, and sorted by crontab content. This will hopefully put all the simillarly schedules lines in all the crontabs together in sort order, so that you can easily pick out conflicting lines and which user contributed them. The resulting output is for reference only, not installation into cron.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .