Script started on Sun 19 Feb 2006 11:59:00 AM EST [root@localhost ~]# cat sayhello #!/usr/bin/perl -w use strict; use warnings; use FileHandle; use File::Basename; my @dirs = qw( /root /root/subdir /var /var/www /var/www/html /var/www/html/bugs ); my $iam = basename $0; foreach my $dir (@dirs) { trydir($dir); } sub tryfile { my ($fname, $text) = @_; my $fh = new FileHandle(); open($fh, ">", $fname) or die "$iam: can't write '$fname' ($!)\n"; print $fh $text; close $fh; (chmod 0777, $fname) or die "$iam: can't chmod '$fname' ($!)\n"; print "Running '$fname' ...\n"; system($fname); print "Running perl '$fname' ...\n"; system("perl $fname"); } sub trydir { my ($dir) = @_; (chdir $dir) or die "$iam: can't change to '$dir' ($!)\n"; print "\e[102m[In directory '$dir']\e[m\n"; tryfile("./hello.pl", "#!/usr/bin/perl -w\nprint \"Hello!\n\";"); tryfile("./do_df.pl", "#!/bin/df"); } [root@localhost ~]# ./sayhello [In directory '/root'] Running './hello.pl' ... Hello! Running perl './hello.pl' ... Hello! Running './do_df.pl' ... Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 33994464 3573692 28666048 12% / Running perl './do_df.pl' ... Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 33994464 3573692 28666048 12% / [In directory '/root/subdir'] Running './hello.pl' ... Hello! Running perl './hello.pl' ... Hello! Running './do_df.pl' ... Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 33994464 3573692 28666048 12% / Running perl './do_df.pl' ... Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 33994464 3573692 28666048 12% / [In directory '/var'] Running './hello.pl' ... Hello! Running perl './hello.pl' ... Hello! Running './do_df.pl' ... Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 33994464 3573692 28666048 12% / Running perl './do_df.pl' ... Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 33994464 3573692 28666048 12% / [In directory '/var/www'] Running './hello.pl' ... Running perl './hello.pl' ... Hello! Running './do_df.pl' ... Running perl './do_df.pl' ... Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 33994464 3573696 28666044 12% / [In directory '/var/www/html'] Running './hello.pl' ... Running perl './hello.pl' ... Hello! Running './do_df.pl' ... Running perl './do_df.pl' ... Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 33994464 3573696 28666044 12% / [In directory '/var/www/html/bugs'] Running './hello.pl' ... Running perl './hello.pl' ... Hello! Running './do_df.pl' ... Running perl './do_df.pl' ... Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 33994464 3573700 28666040 12% / [root@localhost ~]# mount /dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw) /dev/proc on /proc type proc (rw) /dev/sys on /sys type sysfs (rw) /dev/devpts on /dev/pts type devpts (rw,gid=5,mode=620) /dev/sda3 on /boot type ext3 (rw) /dev/shm on /dev/shm type tmpfs (rw) /dev/sda2 on /dos type vfat (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) automount(pid2318) on /misc type autofs (rw,fd=4,pgrp=2318,minproto=2,maxproto=4) automount(pid2349) on /net type autofs (rw,fd=4,pgrp=2349,minproto=2,maxproto=4) [root@localhost ~]# exit Script done on Sun 19 Feb 2006 11:59:13 AM EST #### /root /root/subdir /var #### /var/www /var/www/html /var/www/html/bugs