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
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 to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to write a program for having a pop up or sound after completion of any running process in terminals of any Linux distributions.
Many times I run some command in the terminal and leave it to complete the process but then I have to keep checking that whether it has been completed or not. Any suggestions on how to get started with this?
Here's a solution using notify-send, which is available on most linux desktop environments:
yourCommand; notify-send "Completed !:0" "Exit status: $?"
Another tool for such things is zenity:
yourCommand; zenity --info --text "Command !:0 completed with exit code $?"
Both tools are either already installed on your system or easily installable with the package manager. You might want to wrap the above snippets into an alias or into a custom script that you place somewhere in your $PATH.
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 10 years ago.
Improve this question
How do I change shell in a remote PC? I am logged into a cluster with a Bash and the output I see is
elan#l01:~ $ chsh
chsh: can only change local entries; use ypchsh instead.
elan#l01:~ $ ypchsh
-bash: ypchsh: command not found
Since I have no root privilege there, I can not install ypchsh in the cluster. Is there any other way to change shell without invoking ypchsh?
Note 1:
Browsing, it looks like another user who installed the same software (currently not available for questioning) has .cshrc in his directory, with the right settings. His .bashrc is minimal and has no redirections.
The /etc/passwd has no entry for either of us.
getent passwd
shows entry for both of us, but shows only /bin/bash for both.
Note 2:
The sofware has been developed with autotools, and using bash instead of tcsh is known to have created wrong builds. (I am not changing shell because I fancy it.)
Thank you,
Elan
In your .bashrc, put exec tcsh last.
Once you're in bash in the cluster, why don't you just type tcsh? And if that works, why not just add it as the last line of .bashrc?
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