LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > LinuxQuestions.org > LinuxQuestions.org Member Intro
User Name
Password
LinuxQuestions.org Member Intro New to LinuxQuestions.org? Been a long time member but never made a post? Introduce yourself here.

Notices


Reply
  Search this Thread
Old 04-28-2004, 12:21 PM   #1
JolynnMarie
LQ Newbie
 
Registered: Apr 2004
Posts: 1

Rep: Reputation: 0
shell script fo run auto job in cron


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;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
run shell script on cron varunbihani Linux - Newbie 5 07-08-2005 02:50 AM
How to write a script to run bitdefender antivirus as a cron job? ginda Linux - Software 1 03-10-2005 09:08 PM
how to run this cron job ashley75 Linux - General 5 05-24-2004 12:20 PM
Did my Cron job run? ryedunn Linux - Newbie 2 02-25-2004 09:59 AM
Cron job does not run brentos Linux - General 6 12-12-2003 03:37 PM

LinuxQuestions.org > Forums > LinuxQuestions.org > LinuxQuestions.org Member Intro

All times are GMT -5. The time now is 07:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration