Operating System - Linux
1830233 Members
1897 Online
109999 Solutions
New Discussion

Re: Running commands automatically via SSH

 
tpfraz
Advisor

Running commands automatically via SSH

Hello.
I'm trying to figure how to do something that I think is possible.
I have many users on a server that I would like to give access to one
particular script. However most of them don't know how to use SSH or Linux and I would rather not have to teach them all.
So, what I want to do is setup some kind of SSH client for them that they can simply run. But instead of logging into the Linux box and giving them a command prompt, it just logs in, runs the command, and exits. All while being fairly transparent to the user. Of course the user would at some point have to enter a username and password.
Also, if possible, it would be nice to be able to integrate this into a web page. I was looking at MindTerm for that, the Java applet.

Does anyone know of any way to do this? Or of any SSH clients (preferably free) that have these kind of configuration options?

Also, I don't have access to these users individual machines. So it would be best to have something that I could configure and then hand over to them. Which is another reason a web based client would be nice.

Any help is very much appreciated.

Thanks,
Travis
11 REPLIES 11
Ragu_1
Regular Advisor

Re: Running commands automatically via SSH

Yes, try out this utility called`Putty Link' from the Putty makers. It has been integrated into a script and it is working well.
Share and share alike
Claudio Cilloni
Honored Contributor

Re: Running commands automatically via SSH

to run a remote command through a web page, you can set up a CGI script (using sh, bash or perl) that runs the ssh command; it will connect (ssh could be configured to connect without asking password), execute a command on a remote machine and return the output to the CGI script.

man ssh helps.

hth,
Claudio
Don_89
Trusted Contributor

Re: Running commands automatically via SSH

this should be pretty easy. In each users /home directory, there is a file called .bash_profile. This get executed when a user logs in. Just add two lines to the end of script.

scriptname
logout

After the script runs, it will log them out..
Paul Cross_1
Respected Contributor

Re: Running commands automatically via SSH

a .profile will work, but you could also put the script in the passwd file. ex:

user:x:1000:1000:Joe User:/home/user:/usr/local/myscript

when the user logs in, your script gets executed as their login shell, when the "shell" terminates, their session terminates. This of course is independent of ssh, telnet, rlogin.
Steven E. Protter
Exalted Contributor

Re: Running commands automatically via SSH

A combination of the ptty termianl software and the .profile .bash_profile will do the trick.

There are available for the windows desktop a few ssh tools that work in "DOS" mode and could let you integrate with the Windows Scheduler to do things on an automated basis.

The last time I found a tool like this it was on download.com or tucows.com

This may be more what you are looking for.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Olivier Drouin
Trusted Contributor

Re: Running commands automatically via SSH

if you go with the .profile dont forget to trap signals !!!! So the users cant ^Z or ^D or whatever and find their way to a shell.

What I personnally prefer is to set menu for this kind of users. instead of /bin/bash as their shell in /etc/passwd I put something like /script/menu.sh

menu.sh looks like this

########
!/bin/sh

trap "" 0 1 2 3 15


if [ $SERVER = APP ]
then
/script/appMenu.sh
else
echo "*** Cannot start menu for this server type : $SERVER ***"
fi
exit 0
#######
Martin P.J. Zinser
Honored Contributor

Re: Running commands automatically via SSH

Hi Travis,

depending on what the script does and how much user interaction it does require it really might be easiest to wrap it into a CGI and execute it via a Webserver. Since you do seem to be concerned about security use a secured port (https usually port 443) for the connection.

Greetings, Martin
tpfraz
Advisor

Re: Running commands automatically via SSH

Thanks for all the advise.

Now, if I write a bash script to login automatically via ftp, how would I pass data to it? I need to give it the IP, username, and password. I have never used a shell script as a cgi on a web page so I'm not sure exactly how I would do this.

Also, there are actually multiple machines that users would access this script on (but each user only needs access to one machine, not multiple ones).
So I don't really want to run a web server on each machine just to host this one cgi program.

Any other advise?

Thanks again,
Travis
Martin P.J. Zinser
Honored Contributor

Re: Running commands automatically via SSH

Hello Travis,

up to now the advise has been pretty generic, on the other hand while you obviously have thought about this for a while the questions you have asked have been generic too (maybe even because you have thought about it hard, so it is all obvious to you ;-)

Please give us some more background information. I do assume you endusers are located at (Windows) PCs. Is this correct?
You want them to execute 'a script' running on a few Linux servers. What is this script supposed to do? In you last message you mention ftp. If all you want to do is transfer files from/to the PCs of your endusers there might be easier ways to do this, but we really need some more information to figure this out with you.

Greetings, Martin
tpfraz
Advisor

Re: Running commands automatically via SSH

Martin, you're absolutely right.
In my last post I said FTP but meant SSH. I don't need to do anything at all with FTP.

OK, let me try to explain what I wan to do.
We have multiple servers that we host online games on for customers.
The script that I speak of is used for restarting the individual game. All it does is simply kill the process of the game owned by the user running the script. The game is then restarted automatically from a cron job.

What I want to do is have a central web page that the customers could go to to restart their own game. Just a page that asks for the IP address of their game, their username, and their password.
This info could then be passed to a cgi program of some kind which would in turn log that user in via ssh to their particular server, determined from the IP they entered.
I guess then I would just run the script from that users .profile file and then log them out.

Yes, most of the users are on Windows machines. Maybe a few Macs too, but don't worry about that for now.

So, what would be the best way to pass this info into a cgi?

I hope this made my situation a bit clearer.

Thank you all very much.
Travis

Martin P.J. Zinser
Honored Contributor

Re: Running commands automatically via SSH

Hello Travis,

I think the idea with the central Webpage is a good one. Authentication can be done in the Webserver and the username can be retrieved by the script from the environment. You will obviously need a simple "database" to make sure users only stop their own games. You could use the NET::SSH perl module to connect from the webserver to the other linux systems. You can pass a command/scriptname to SSH directly, so you do not even have to fiddle with the .profiles.

Obvously all of this could be implemented in a number of languages other than Perl (php, Python and Java come immediatly to mind) so take the one you are most comfortable with.

Greetings, Martin