#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Unix command in perl script


    Dear all,

    Glad if you can help me with the following issues:

    I need to do script that can:
    1. Get file from shell in unix?
    2. Run on this file commands that I do in the command line in unix.
    Something like:
    1. Get a file moo from the current folder.
    2. And run the command: tar cvf moo.tar moo

    Thank you all!
    Have a great day
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    833
    Rep Power
    496
    Possibly something like this:

    Perl Code:
    my $return_status = system ("tar cvf moo.tar moo");
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by Laurent_R
    Possibly something like this:

    Perl Code:
    my $return_status = system ("tar cvf moo.tar moo");
    Thank you very much for the reply.
    But the file will change from folder to folder so actually the moo needs to be read into $file and then I need to use this parameter in the system line.

    Do you know how to get the moo file from the folder into $file parameter?

    Thanks again!!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    1. Get file from shell in unix?
    That's a little vague.

    You can pass the filename to the script as an arg and it will be in the @ARGV array.

    Or, you could use the glob function or diamond operator to get the filename(s).

    Or, you could use the File::Find module if you need to recurse a directory tree.

    Please provide more details on what you need and post your code and explain how it fails to do what you need.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    833
    Rep Power
    496
    Originally Posted by MA1985
    Thank you very much for the reply.
    But the file will change from folder to folder so actually the moo needs to be read into $file and then I need to use this parameter in the system line.
    Just change it to:

    Perl Code:
    my $return_status = system ("tar cvf moo.tar $file");


    or possibly to something like:
    Perl Code:
    my $tar = $file . ".tar";
    my $return_status = system ("tar cvf $tar $file");

    depending on what you need exactly.

    Originally Posted by MA1985
    Do you know how to get the moo file from the folder into $file parameter?
    As for reading the moo filename into $file, there is nothing complicated about reading file names from a directory on disk (Fishmonger has given some solutions in the post above), but you are not telling us enough about how we should know which file to pick up from a directory.

IMN logo majestic logo threadwatch logo seochat tools logo