This may be amazingly easy to you guys, but I cannot understand why it is not working. Typically I use 'cd' to change to a directory I wish the command executed in and its fine. But, the following will always place an empty tgz file in the root directory and nothing goes to the backup directory. What I am tryin to do is create a backup script that will backup some directories that cannot get backed up with the normal ones that occur. It seems that simply the 'cd' is not working? It is being run as root so it should be able to go anywhere. I am pretty sure I have used 'cd' before with success. Another question I had was if the tarring processes would take a while would it cause problems? So, would it get to the 'mv' functions and so on before it completes the tarring thus causing problems? ...or does perl wait until each command is done before moving on? Any help would be great! Thanks
system ("cd /path/to/dirs"); system ("tar -czvf dir1.tgz dir1/"); system ("tar -czvf dir2.tgz dir2/"); system ("tar -czvf dir3.tgz dir3/"); system ("mv /path/to/dirs/dir1.tgz /backup/dir1.tgz"); system ("mv /path/to/dirs/dir2.tgz /backup/dir2.tgz"); system ("mv /path/to/dirs/dir3.tgz /backup/dir3.tgz");

In reply to cd in perl not working? by metal_cd

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.