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(APTSCRIPT,2); print APTSCRIPT <<'EOF'; #!/usr/bin/perl print "replace this script with the logic of the download of the deb file"; EOF close(APTSCRIPT); closedir(AUTOMATION); closedir(ETC); } }