shell script fo run auto job in cron
:newbie: :cry: I need to write a shell script that asks a user to input a single-line command that they want to have executed once a week. Ask the user to input the day of the week on which they want the command to be executed. I have submit their command as a correctly formatted cron job. Will this work?
#!/usr/bin/perl -w use strict: print "enter commnad to be run: "; chomp (my $ command = <STDIN> print "Enter the day of the week to run: "; chomp (my $day = <STDIN>); $day =~ tr/A-Z/a-z/; unless ($day =~ /^(m|tu|w|th|f|sa|su)/) { print "Error: You did not enter a valid week day\n"; exit 0: } if ($day =~/^m. *$/) { $day = "mo"; } if ($day =~ /^tu. *$/) { $day = "tu"; } if ($day =~ /^w. *$/) { $day = "we"; } if ($day =~ /^th.*$/) { $day = "th"; } if ($day =~ /^f.*$/) { $day = "f"; } if ($day =~ /^sa.*$/) { $day = "sa"; } if ($day =~ /^su.*$/) { $day = "su"; } my %week = ("su","0","m","1","tu","2","we","3","th","4","fr","5","sa","6"); open my $fh, ">/tmp/ctab" or die "$!"; print $fh "0*** $week{$day} $commnad \> \/dev\/null 2\>\$1\n"; close $fh; |
All times are GMT -5. The time now is 05:37 PM. |