Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm looking for a solution for automate remotely connecting to a linux squid cache server via SSH. Then a script would need to run to stop squid and then restart squid with a different squid.conf file. The entire process needs to be automated because it will need to be ran at around 2am in the morning once or twice a week. Thanks for any help with this problem.
This is a job for cron.
Write a script that do what you need and put this script to run by cron at 2am once a week.
Let say your script is /usr/local/sbin/myscript.
the following line in root's crontab would run myscript at every sunday 2:00am:
Code:
#min hour dom month dow command
#0-59 0-23 1-31 1-12 0-7
# 0, 7 is Sunday. Names are ok.
0 2 * * Sun /usr/local/sbin/myscript
The script basically needs to run only the following command:
ssh user@host command
where "command" is a program (script) on the remote host to create new squid config, stop squid and restart it.
To be able to automatically login using SSH, you should put the public key of your host in ~user/.ssh/authorized_keys file on the remote machine.
this needs to be setup on demand not at the same time every week. Could be some weeks where it is not ran. The script will be swiching squid to reverse proxy 3 web servers to 3 differnt web servers and this needs to be automated based on web app release schedules.
You can use timmeke's suggestion or as I do, comment the line when I do not want it to be run and un-comment it in an on demand base.
Also, you can use the command "at 2:00" to setup one time execution.
Thanks for the suggestions. I like the "ssh user@host command" method. I just need more info on how to set this up. I don't know how to setup the keys (~user/.ssh/authorized_keys) Ideally we'd want this to be fired off from a Windows machine with no interaction needed.
On Windows, I recommend getting PuTty or some other SSH client application, preferably with a command line interface.
The "ssh user@host" command probably only works on Linux, not on Windows.
Was just about to post a little script that I made last year it will upload a ssh key to a server of your choice. You can then modify it a bit to run a command on the remote hsot via ssh, I did this and it seems to work fine, hopefully remember exacktly what I did.
The first time you use ssh to connect to another machine it will make them for you, but you can make the .ssh directory yourself it you want. The script I posted will make the directory on the remote host if it doesn't already have one.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.