How To Pass String Variable As Command Parameter In Shell Script?

Hello Friends,

I want to pass string variable with its value taken by user as command parameter in shell script, example below:-

echo "Enter New Password:="
read password


perl -pi -e
's/PASSWORD=.*?,/$password,/' abc.txt

Please let me know...
Thanks In advanced.


Similar Content



How To Return From Shell 'read' Command Passed In Expect Script?

I have a shell script that calls an expect script I wrote to ssh login to another host and get user input regarding that host's network configuration. I pass four arguments to the expect script: the remote host ip address, the username, the password, and the list of commands to run. My expect script is below:

#!/usr/bin/expect
# Usage: expectssh <host> <ssh user> <ssh password> <script>

set timeout 60
set prompt "(%|#|\\$) $"
set commands [lindex $argv 3];

spawn ssh [lindex $argv 1]@[lindex $argv 0]

expect {
"*assword:" {
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

"you sure you want to continue connecting" {
send -- "yes\r"
expect "*assword:"
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

timeout {
exit }

expect -re $prompt
send -- "exit\r"
}

The script runs well, except that if I send a command such as 'read' that requires user input, the script does not continue or exit after the user presses enter. It just hangs.

The commands I pass to the expect script and it's call are as follows:
SCRIPT='hostname > response.txt;netstat -rn;read net_card?"What is the network interface card number? " >> response.txt; read net_mask?"What is the subnet mask? " >> response.txt'

/usr/bin/expect ./expectssh.exp $hostip $usr $pswd "$SCRIPT"

Any suggestions on how I can pass a command to my expect script that requires user input without it hanging?

On a side note because I know it will come up - I am not allowed to do key-based automatic SSH login. I have to prompt for a username and password, which is done from my main shell script.

Thanks for any suggestions and help you can provide!

How Can I Enter Password Automatically For An Script?

Hello.
How can I write an Script that enter my password for "sudo" command automatically?
for example, I want to run a command that need root permission and when I write it in a bash script, it ask me "sudo" password for user but how can I automate it?
Can it possible for other program like logging via SSH too?

Thank you.

How Can I Grep Variable?

I want to And search grep shell

but It's hard to grep variable


---------------------------------------------------------------
#!/bin/bash


if [ $# -eq 0 ]
then
echo "Ussage: phone searchfor [...searchfor]"
echo "(You didn't tell me what you want to search for )"

else

pass=0
find=""

for idx in $*
do
if [ -n "$idx" ]
then
if [ $pass -eq 0 ]
then
find=$(egrep "$idx" mydata)
pass=1

else

find=$("$find" | grep "$idx")

echo $find
fi
fi

done

if [ -z "$find" ]
then
echo "There is no such thing"
else

echo $find | awk -f display.awk

fi

fi

-----------------------------------------------------

there is one error : command not found

in find=$("$find" | grep "$idx")

how can I grep variable and store it into variable?

Compare Given Password And Regexp With Password Length

Hello friends,

I want to compare regexp and password, Including password length using shell script.

password=az*12345
regexp=^[a-zA-Z]{2}[*][0-9]{5}$

please let me know
thanks in advance.

Passing Password To Encfs

There is an option in encfs:

--extpass=program Use external program for password prompt

I want to use such program for this:

#!/bin/bash
zenity --entry --title="password dialog" --text="Enter your _password:" --hide-text

But how can I pass such obtained password to entfs call?

Any idea?

How To Copy File From Remote Host To Local Host Then Delete From Remote Host

I have an expect script to SSH to a remote host and obtain some user inputs and information about the server/network configuration. The responses are saved in a text file that I then need to copy to my local host so that I can read the lines into variables for use in the parent shell script.

Is there a way to do this without needing to enter the username and password for the local host to use function scp? I have tried the following in my expect script to no avail:
Code:
spawn scp $usr@$host:$flnm .
expect {
	-re "(.*)assword:" { 
		send -s "$pswd\r"
	}
}

I have also tried to directly scp the file and enter the username and password to try to debug the issue, and that doesn't work either:
Code:
spawn scp file.txt user@host:file.txt
expect {
	-re "(.*)assword:" {
		send -s "password\r"
	}
	"you sure you want to continue connecting" {
		send -s "yes\r"
		exp_continue
	}
}

In both scenarios I have used exp_internal 1, and there are no errors. But I do not end up with the file on my local host.

Following the copy, I would like to delete the file from the remote host. Any suggestions on how to accomplish this?

Bash User Input With Static Value Validation

So I created this big script and want to ask for username and set a variable, however if the username exist in the username variable then continue with script otherwise ask the user to enter his name.

Flow:
-- start script "Enter User Name"
-- ask user to input username
-- if username is blank or different value then put that username in $USERNAME variable
-- then continue with the rest of the script

-- next time this user runs the script it will have his name loaded so he just presses enter to continue with the script.

-- If it is NOT the same user then, new user can erase existing input and enter a new name.

Hope it makes sense...

Thanks in advance for the help.

Perl Script Not Running Via Cron

Hi All,

I have perl script which I am trying to run on 1st Monday via cron job.
So I scheduled it as follows:

0 0 1-7 * * root ["$(date '+%a')" = "Mon"] && /usr/bin/perl script.pl

But then it didn't run so checked cron log and it seemed like its missing the command. so added a \ in front of %a and then it picked up the whole command as per cron log.

But still it didnt ran the script. I then change the script to just && echo "test">/tmp/test

Still nothing. if I run it as /usr/bin/perl script.pl it runs though

Thanks in advance.

Changing Password To A User

Hi
When i tried to change the password for a particular user as a root by using usermod command I didn't see any error at that time.But later when I tried to login again it is not accepting the new password as well as old password.Why its happening?Any help....

How Can I Get My Simple Script Working

hi guys,

sick of typing sudo yum install package

so i wrote...or rather am trying to right a simple script to do this
with a simple command:

heres what i have:

#!/bin/bash
echo "Enter package name to install..."
read $P
sudo yum install $P

it doesnt seem to want to take the variable...it just runs
sudo yum install ...$p is ignored...i also tried "$p" but this
doesnt work either...what is the correct syntax to get a command to read a variable...is this possible...aaaaaaah it must be.