Hi, (this was also posted on nntp.perl.beginners, but I don't expect an answer there). I'm just stumped by this one. It all started when I was trying to work out a backup method of backing up all subdirs of /home/user as individual tarballs. So I wanted to copy everything from the user's top level directory to a temporary backup directory. This included all hidden files, hidden directories, and plain files in /home/user. Well, I did some testing as myself, and all seemed to be going well, then I moved the script to /, and see what happens when root ran it. Things went wrong, root runs the same file from /, and it misses plain files like /home/user/sig. I made a little test case to demonstrate the problem.
The following script is run by root in /home/user: /home/zentara/backup-homex ------------------------------------------------------------------------------------------
#!/usr/bin/perl -w @users=('/home/zentara'); #put all user-root hidden files and hidden dirs into 1 temp dir #this makes it easier to backup second level subdirs foreach $homedir(@users){ opendir DIR, $homedir or warn "Cannot readdir $homedir:$!\n"; @files = grep !/^\.\.?$/, readdir DIR; foreach (@files){push @movem,$_ if -f} foreach (@files){push @movem,$_ if ($_ =~ m!^[.]!)} print "@movem\n"; print "##############################################\n"; } exit;
------------------------------------------------------------------------------------------
When the above script is run as user or as root in /home/zentara the output is good:
x z z1 zz sig sig1 sig2 sigs wxyz .Xmodmap sig.perl .bashrc .fvwm2rc
.bash_history backup-homex .Xdefaults .Xauthority .profile .Xresources
dontfeedtrolls .xinitrc wxyz-root .kc .le .mc .qt .ddd .kde .pan .pfm
.ssh .netscape .designer .babygimp .gftp .gimv .fvwm .java .kde2 .sane
.skel .ssh2 .vifm .wine .xmms .Xmodmap .tkalbum .bashrc .gnome2_private
.tkphone .dosemu .mozilla .gconfd .gnome2 .gphoto .gqview .glabels
.gkrellm .fvwm2rc .acrobat .gnucash .gimp-1.2 .pgaccess .regexp
.ptknotes .nautilus .bash_history .mhwaveedit .glameswap .autozen
.kalyptus .antiword .Xdefaults .gnome-desktop .Xauthority .profile
.jpi_cache .gnome_private .Xresources .xinitrc .pornview .adobe .cedit
.dillo .gconf .foxrc .gnome .gnupg .gtklp .links .tkfax .sweep
.cddbslave .roadmap .rolodex .sylpheed .TinyCA .emacs.d .wine.bak
##############################################
------------------------------------------------------------------------------------------
When the above script is run by root from /, the output misses some plain files, notably sig, but many are missing, seemingly random:
wxyz backup-homex .kc .le .mc .qt .ddd .kde .pan .pfm .ssh .netscape
.designer .babygimp .gftp .gimv .fvwm .java .kde2 .sane .skel .ssh2
.vifm .wine .xmms .Xmodmap .tkalbum .bashrc .gnome2_private .tkphone
.dosemu .mozilla .gconfd .gnome2 .gphoto .gqview .glabels .gkrellm
.fvwm2rc .acrobat .gnucash .gimp-1.2 .pgaccess .regexp .ptknotes
.nautilus .bash_history .mhwaveedit .glameswap .autozen .kalyptus
.antiword .Xdefaults .gnome-desktop .Xauthority .profile .jpi_cache
.gnome_private .Xresources .xinitrc .pornview .adobe .cedit .dillo
.gconf .foxrc .gnome .gnupg .gtklp .links .tkfax .sweep .cddbslave
.roadmap .rolodex .sylpheed .TinyCA .emacs.d .wine.bak
##############################################
Can someone shed some light on why this happens? It has something to do with running it from /. I have got around it by chdiring to /home/user to let root run the script from there, but I really would like to know what is going on. Thanks.

In reply to losing files when run from / by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.