Link to home
Start Free TrialLog in
Avatar of Shamsul Kamal
Shamsul Kamal

asked on

bash script

Hi,

I have a question, like to require  your assistance, want a bash script which work same like as below mentioned perl script:

==================================================
#!/usr/bin/perl

my %OPTS = @ARGV;
my $user = $OPTS{'user'};

$task = "mv /backup/cpbackup/daily/$user.tar.gz /backup-delete/$user.tar.gz";
$contents = `$task`;
exit;

==================================================

BR
Javaid
Avatar of Steven Vona
Steven Vona
Flag of United States of America image

Since the first declarations are never used I imagine this would have the same effect:

#!/bin/bash

task="mv /backup/cpbackup/daily/$user.tar.gz /backup-delete/$user.tar.gz"
contents=`$task`
exit
Presumably the argumets being passed to your perl script are
perlscript.pl user username

the bash script that savone provided has to be modified to;
#!/bin/bash

task="mv /backup/cpbackup/daily/$2.tar.gz /backup-delete/$2.tar.gz"
contents=`$task`
exit 

Open in new window


If you perl script is called with various arguments for historical reasons and user username are not the only arguments on the line and they are not the first two.  Further checks within the bash script have to be done to evaluate each argument to see whether it is the string 'user' and then use the next argument.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shamsul Kamal
Shamsul Kamal

ASKER

superb  ozo, yes it's working according to desire results :)

BR
Javaid