LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Shell Scripting (https://www.linuxquestions.org/questions/linux-software-2/shell-scripting-461165/)

greenberet 07-05-2006 06:52 AM

Shell Scripting
 
i have a program which my ISP has provided me to authenticate myself so that i can use the web.

It is called 24 online Client.

so i type
./24onlineClient -u [username]
then it says
Password:
the i type the password and then it authenticates me

I would like it to logon automatically every time i start my pc.

so i wrote a shell script

and put this command in and i plan to put it in rc.local or something.

But i have still not figured out how to provide this program with the password so that it automatically logs in without asking me for the password.

i tried ./24onlineclient -u [username] < pass.txt

and stored the password in pass.txt but it still asks for the password.

So any idea how i can get this done.

I am a newbie, so please dont use complicated terms.

DrOzz 07-05-2006 07:03 AM

I don't know if this would work or not, because I can't really test it without that script, and even if I did have it I wouldn't be able to since I wouldn't authenticate with your ISP, but I'll give ya something to start with as a shot in the dark :
Code:

#!/bin/bash
# Define your authentication information
USER="YOURUSERNAME"
PASSWORD="YOURPASSWORD"

# And this is what I think may work
echo -e "${PASSWORD}" | /path/to/client/24onlineclient -u ${USER}

# If you have to type password twice then just remove the next # symbol and use :
# echo -e "${PASSWORD}\n${PASSWORD}" | /path/to/client/24onlineclient -u ${USER}

I have no idea if that will work, but I guess it'll get ya started in your attempts ;)

What I would try instead of keeping on rebooting, is just fill in your username and password above in the script, and just run the script and see if your online.

greenberet 07-05-2006 10:35 PM

Hey i typed in that script but it still asks me for the password. I suppose that pipe is as good as a redirect
< symbol which is also not working. If you want to test it out, the client is available at

http://prdownload.berlios.de/cyberoa...x86-1.0.tar.gz

of course you wont get authenticated but all you have to check is that whether it prompts for the password or not. Just enter any 24online online server. It will probably work.

theNbomr 07-05-2006 11:39 PM

If you don't get a real solution, I can describe a MONUMENTAL hack to accomplish this, using Gnu screen, and stuffing characters into it from a shell script. It's a bit complicated, so I'll hold off until a time of last resort.

--- rod.

sameep 07-06-2006 03:06 AM

Hi... there is an alternative soultion.. I dont know how to get ure password into the script but u can get the alternate cyberoam client. There are a couple of alternatives to Cyberoams 24Online... you can google for them.. One which i used was Slyberoam.


P.S. u can also try linc-daemon
sourceforge.net/project/showfiles.php?group_id=55535


Hope it helpss

sudya 07-06-2006 03:35 AM

there is an option -f that will write a config file for you. Try to play around with that file, I saw there are couple of options about password. Save password and password fields might be your solution

greenberet 07-06-2006 06:09 AM

i am not interested in the client.

I am interested in the shell scripting part.

So even if the client provides any option it does not matter.

I want to know how to supply the password via shell script.

greenberet 07-06-2006 06:10 AM

i am not interested in the client.

I am interested in the shell scripting part.

So even if the client provides any option it does not matter.

I want to know how to supply the password via shell script.

please help.

greenberet 07-06-2006 06:17 AM

sorry for the double post. I think cyberoam has an option of auto login.

But there must be some way to do it by shell scripting.

hey thenbomr, i dont mind that solution of course, if you can explain it of course.

gkiagia 07-06-2006 09:08 AM

I would also try this:
Code:

#!/bin/bash
# Define your authentication information
USER="YOURUSERNAME"
PASSWORD="YOURPASSWORD"

# And this is what I think may work
echo -e "${PASSWORD}\n" | /path/to/client/24onlineclient -u ${USER}

The difference is that the password now ends with a newline character, which is what the enter key inserts. Normally, when it prompts you for the password, you type it in and then you press enter. The pipe passes the password to the program, but it doesn't press enter! So, with the \n character it might work.

I have tried the same trick in the past using a Qt/C++ program that tricks /usr/bin/sudo and passes it the root password to install rpm files. Here is part of the code:
Code:

QString password;
password = "mypassword";
password.append("\n"); // add a newline character at the end of the password
       
//Create process to do installation
rpminstall = new QProcess(this);
rpminstall->addArgument("/usr/bin/sudo");
rpminstall->addArgument("/bin/rpm");
if (vvBox->isChecked() )
    rpminstall->addArgument("-Uvv");
else
    rpminstall->addArgument("-Uvh");
if (forceBox->isChecked() )
    rpminstall->addArgument("--force");
if (nodepsBox->isChecked() )
    rpminstall->addArgument("--nodeps");
if (testBox->isChecked() )
    rpminstall->addArgument("--test");
rpminstall->addArgument(filename);
       
if ( !rpminstall->start() ) {
// error handling
QMessageBox::critical( 0, tr("Fatal error"), tr("Could not start the rpm command."), tr("Quit") );
exit( -1 );
}
rpminstall->writeToStdin(password); // pass the password to sudo


theNbomr 07-06-2006 10:21 AM

It looks like the dialog to accept the login parameters is not reading from stdin, so no amount of stdio redirection is going to work. Another tack must be taken.

One method is to run the program inside of a gnu screen session. Screen allows one to 'stuff' characters into its console/tty input at a bit lower level, so we can 'type' into things that aren't reading stdin.

Code:

#!/bin/sh
#  ========= rc.local ===========
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.


PATH=$PATH:/usr/local/bin
export PATH

SCREEN_24ONLINE="24 Online"
USER_24ONLINE="JoeBloggs"
PASSWORD_24ONLINE="horty.florty"

#
#      We run the client application inside of Gnu screen sessions, so
#      we can monitor them and send commands to their interactive shells. We need
#      a way to create a tty for them at boot time. The Xvfb provides a virtual X server
#      to support an xterm that can in turn support a bash shell.
#
echo "Launching X virtual framebuffer"
Xvfb :1 -fbdir /tmp &

# We really should do something more robust for this...
echo "Snoozing while the virtual X server finds it's fonts..."
sleep 10

export DISPLAY="localhost:1"

echo "Starting 24 Online xterm/screen"
xterm -e screen -S "$SCREEN_24ONLINE" bash &

#
#      Q: So what is all this `echo -ne '\015'` stuff?
#      A: We are stuffing characters into a Gnu screen session, and
#          this is how we stuff a 'newline'


echo "Starting 24 Online"
screen -S "$SCREEN_24ONLINE" -X stuff "cd /dir/where/the/program/lives"`echo -ne '\015'`
screen -S "$SCREEN_24ONLINE" -X stuff "./24onlineClient -u $USER_24ONLINE"`echo -ne '\015'`

# Sleep a second while the program digests the entry... (may be required, or not)
sleep 1

screen -S "$SCREEN_24ONLINE" -X stuff "$PASSWORD_24ONLINE"`echo -ne '\015'`


echo Done
# ======================== End 24 Online setup ============================
#


The above is a modification of a method I use for launching an application at boot time.

The session will run as root, since it is run from rc.local. You may be able to use 'su' to change the user id when launching either screen or your 24 Online client. In order to access the running session, you can re-attach to the screen session with
Code:

screen -S "24 Online" -x
or, if you aren't already root
Code:

screen -S "root/24 Online" -x
If you are not the original owner of the screen session (probably root), you will have to have set up screen in multiuser mode by adding a line
Code:

multiuser on
to /etc/screenrc

You can test things using a normal shell script, and once the wrinkles are ironed out, put it into rc.local
I suggest reading up on gnu screen, a priori. Note also the inherent insecurity of embedding a password into a plaintext file. Caveat emptor.

I told you this was a monumental hack, did I not?

Enjoy.

--- rod.


All times are GMT -5. The time now is 02:58 PM.