Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Hello People i'm trying to do an script bash using a expect part to enter a server and keep alive the session, my script is as follow:
#!/bin/bash
/usr/bin/expect << eof
spawn ssh user#server
set prompt ":|#|\\\$"
expect "password"
interact
eof
I can enter to the server but the session dies after a second and return to my local computer,
Can any one help me please?
The problem is because of HEREDOC usage. Instead you could quote the whole code as
#!/bin/bash
/usr/bin/expect -c '
spawn ssh dinesh#myhost
set prompt ":|#|\\\$"
expect "password"
interact
'
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is there any way to edit the ssh command in such way that 'ssh hostname' runs a bash script first before its standard function
Edit: Note that the ssh command's name stays the same, without adding anything to it.
Use shell alias. In your case:
alias ssh="echo 'hi'; ssh "
From now on, when you type ssh in the terminal, the shell will expand the alias.
In a shell script, you would need shopt -s expand_aliases for it to work.
You can use ProxyCommand.
Add to your ~/.ssh/config:
Host hostname
ProxyCommand /path/to/bash-script
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to access my local variable in remote server. Which command should I use.
Ex.
cmd:
SERVER 1
VAR=2
ssh unix-user#remote-server-name "bash abc.sh"
REMOTE SERVER:
cat abc.sh
echo $VAR
output should get 2.
Set the variable directly on the remote side:
ssh unix-user#remote-server-name "export VAR=2; bash abc.sh"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to create a BASH script to check if the Linux Web Server is "up" and run it automatically once every five minutes from the "internal" Linux Server and send an e-mail from from the script if a failure is detected.
Can someone please help me to make the script? Since i'm new to scripting.
If you want verify if a Web server is up and running, make a script to verify if exist a PID or process named with "apache" - Considering that you have web server Apache - this will show you not only if the machine is up and running but also if the webservice is working.
For a more professional tool, you can use Nagios.
Something like:
while sleep 60; do
if ! wget -o /dev/null www.example.com/; then
sendmail admin#example.com <<EOF
Subject: www.example.com is down
www.example.com is down, please do something.
.
EOF
fi
done
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am working on a Linux server, I have access to a directory but I am not allowed to write anything to that directory. I can run commands from system prompt. Now I have to find values of specific field of some files in that dir and do some comparisons. I have a script on a test server can do that. But I can't install my script to the server, I am asking if there is anyway I type a specific command, then I can write and run a shell program without saving the program? Thank you!
If you have the script on another host, you can run it this way:
wget http://your.host.net/script -O- | sh -s
If the host is not accessible via HTTP, you can use any other protocol you want.
Also you can write a script direct in a shell:
sh -s <<EOF
echo Hello
echo I am script
echo Nice to meet you
EOF
You can use backtics to execute the result of another command.
`wget /path/to/your/script/stored/remotely -O-`
(you might use sftp to fetch the script instead)
Another option is to write a program that uses a tty to control an ssh session, then the script is stored on the ssh client but the commands run on the server. Perhaps the expect tool would help with that.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I am trying to make batch commands (sh) on linux for start, stop and restart my web server lighttpd, with partial success.
Ideally, I would like to doubleclick icon and nothing more to do a job.
Now, on doubleclick appear dialog "Do you want to run "START.sh", or display its contents?" and "START.sh" is an executable text file." with Run in terminal, Display, Cancel and Run buttons. Run in terminal do a job after typing password.
My script look as follows:
#! /bin/bash
sudo /bin/bash /etc/init.d/lighttpd start
echo
echo -n " [ENTER] to continue... "
read var_keypress
Is here any way for my script to run without prompted dialog and that I don't need to type password every time?
You can configure sudo to be usable with no password as described here:
http://www.linuxscrew.com/2008/06/22/configure-sudo-nopasswd/
Be sure to let sudo only run specific commands without password, not all.
You could avoid that with a system init script (ln -s /etc/init.d/lighttpd /etc/rc2.d/S99lighttpd on Debian) or with a crontab entry for #reboot