Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I wanted to create a perl script to check if a directory exists, and if it doesnt i want to crate one.It doesnt work in /etc,whereas the same code runs in other directories.any help would be appreciated.
my $username = getpwuid( $< ); print "$username\n"; if($username ne "root"){ print "please run this script as root.\nsudo perl automation.pl\n +"; exit; }else{ opendir(ETC,"/etc"); unless(-d "Automation"){ mkdir("Automation"); opendir(AUTOMATION,"Automation"); + open(CRONTABFILE,">crontab"); flock(CRONTABFILE +,2); $cronjob = "0 12 * * * /usr/bin/perl /etc/Automation/aptscript.pl"; + print CRONTABFILE "$cronjob"; close(CRONTABFILE); + open(APTSCRIPT,">aptscript.pl"); flock(APTSC +RIPT,2); print APTSCRIPT <<'EOF'; #!/usr/bin/perl + print "replace this script with the logic of the download of the deb f +ile"; EOF close(APTSCRIPT); closedir(AUTOMATION); closedir(ETC); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: detecting directory in perl
by Corion (Patriarch) on Sep 08, 2016 at 18:15 UTC | |
|
Re: detecting directory in perl
by stevieb (Canon) on Sep 08, 2016 at 18:11 UTC | |
|
Re: detecting directory in perl
by davido (Cardinal) on Sep 09, 2016 at 05:50 UTC | |
by MidLifeXis (Monsignor) on Sep 09, 2016 at 14:43 UTC | |
by davido (Cardinal) on Sep 09, 2016 at 15:17 UTC |