- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Crontab Filtering
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2008 05:12 AM
10-06-2008 05:12 AM
Crontab Filtering
We need to create a script to find all the programs or scripts running at a particular time from crontab.
1. Should have an option to search by name or using Shell's meta characters.
2. Should have an option to search by Minute.
3. Should have an option to search my Hour.
4. Should have an option to search by day.
7. Should have an option to search by month.
8. Should have an option to search by Weekday.
for Ex : filter.sh -h 22 -day 10 -f /var/spool/cron/crontab_file
The above script should display all the scprits running at 22:00 and 10th of each month. /var/spool/cron/crontab_file is sample crontab file.
Could anyone throw some light on this?
- Tags:
- crontab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2008 05:34 AM
10-06-2008 05:34 AM
Re: Crontab Filtering
If all you are doing is ANDing all of your options you might be able to grep and awk to select the fields. But you would have to handle "*" and ",".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2008 06:02 AM
10-06-2008 06:02 AM
Re: Crontab Filtering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 11:51 PM
10-08-2008 11:51 PM
Re: Crontab Filtering
You can create complex queries using case statement and shift. It's not fool proof thou.
ex.
filter.sh -h 22 -day 10 -f file
until [ -z $1 ]; do
case $1 in
-h)
some_command $2
break
;;
-day)
some_other_command $2
break
;;
-f)
some_third_command $2
break
;;
esac
shift
done
This is untested (not near a machine) so I'm not 100% sure that break won't destroy the "until" statement. But there's ways around that too. You could just ignore doing a break and let it pass.
But what you need is something that goes throu every line with a regexp and then sorts it out and I think it'll make a lot of nested if-else-then statements.
But I think Michael has the better plan... cat/grep/tail/head the logfile and just get the dates from there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2008 03:41 AM
10-09-2008 03:41 AM
Re: Crontab Filtering
This is not the complex query I had in mind. I was thinking of combinations of queries 1 through 8 with AND and OR. Possibly searching for multiple names or hours, etc.
It looks like yours does an OR.
>until [ -z $1 ]; do
Typically I only use while and count parms. Yours will fail if using "set -u".
while [ $# -gt 0 ]; do
>that break won't destroy the "until" statement.
I think you want to use just ";;" to terminate each case label. break gets you out of the until.
Also, you need to do "shift 2".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2008 06:30 AM
10-09-2008 06:30 AM
Re: Crontab Filtering
Agreed, it'll be tricky and quite long if you want it to take AND parameters. It is possible thou, that was just a quick example on how to get multiple parameters without the need to have them at the right position.
> Also, you need to do "shift 2".
Not really, unless you have a case label that will match the parameter value.
Like having -2 as a case label whilest sending something like "file.sh -degrees -2" (in which case you're absolutely right, shift 2 would solve it).
This is quite easily solved by always saying that you want --degrees instead of just -degrees :)
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2008 03:38 PM
10-09-2008 03:38 PM
Re: Crontab Filtering
I was talking about your example. But it would be better to have two shifts in case you had various types of options taking different parms:
while [ $# -gt 0 ]; do
case $1 in
-h)
some_command $2
shift
;;
...
*) echo "bad option: $1"
;;
esac
shift
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2008 06:32 AM
10-15-2008 06:32 AM
Re: Crontab Filtering
#!/usr/bin/perl
$numArgs = $#ARGV + 1;
foreach $argnum (0 .. $#ARGV) {
$argument=@ARGV[$argnum];
if ($argument eq "-day" or $argument eq "-d") {
if (@ARGV[$argnum+1] =~ m/^[0-9]+$/) {
$day=@ARGV[$argnum+1];
} else {
print "@ARGV[$argnum] should only be followed by a digit.\n";
$exitcode=1;
}
}
if ($argument eq "-hour" or $argument eq "-h") {
if (@ARGV[$argnum+1] =~ m/^[0-9]+$/) {
$hour=@ARGV[$argnum+1];
} else {
print "@ARGV[$argnum] should only be followed by a digit.\n";
$exitcode=2;
}
}
if ($argument eq "-minut" or $argument eq "-m") {
if (@ARGV[$argnum+1] =~ m/^[0-9]+$/) {
$minut=@ARGV[$argnum+1];
} else {
print "@ARGV[$argnum] should only be followed by a digit.\n";
$exitcode=3;
}
}
if ($argument eq "-month" or $argument eq "-M") {
if (@ARGV[$argnum+1] =~ m/^[0-9]+$/) {
$month=@ARGV[$argnum+1];
} else {
print "@ARGV[$argnum] should only be followed by a digit.\n";
$exitcode=4;
}
}
if ($argument eq "-weekday" or $argument eq "-w") {
if (@ARGV[$argnum+1] =~ m/^[0-9]+$/) {
$weekday=@ARGV[$argnum+1];
} else {
print "@ARGV[$argnum] should only be followed by a digit.\n";
$exitcode=5;
}
}
}
if ($exitcode) {
exit $exitcode;
} else {
# Run your script
print "$hour $minut $day $month $weekday\n";
}
- Tags:
- Perl