1828586 Members
2546 Online
109982 Solutions
New Discussion

Help Needed for Script

 
SOLVED
Go to solution
Karthick K S
Frequent Advisor

Help Needed for Script

Hi,

I write a one script for quit the application , if i quit the db it should comeout from telnet sessions itself and also CTRL-C should not work because only quit only can quit the session

below the script i tried but if i quit its going to $ prompt and not comeout from telnet session

pls help anyone

dbcheck()
{
if [ $DB123 = "quit" ]
then
clear
exit 0
else
getdb
fi
}

getdb()
{
clear
echo "\n\n\n\n\n
Enter the db name you wish to connect to \n or quit to exit : \c"
read DB123

dbcheck
}

getdb


17 REPLIES 17
Arunvijai_4
Honored Contributor

Re: Help Needed for Script

Hi Karthik,

You can try two options,

#1. Try logout, it will logout from script shell.

#2. Create an alias for it, just like "./myscript.sh; exit"

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Karthick K S
Frequent Advisor

Re: Help Needed for Script

Hi Arun,

Can you give some example how to do
RAC_1
Honored Contributor

Re: Help Needed for Script

To get out of telnet session you need to put in "exit" command.

To disable operation of ^c, you need to set the trap to ignore ^c.
trep '' 3
3 is interrupt signal.
There is no substitute to HARDWORK
RAC_1
Honored Contributor

Re: Help Needed for Script

dbcheck()
{
if [ $DB123 = "quit" ]
then
clear
break
exit 0
else
getdb
fi
}
logout # logout is quit is entered.

getdb()
{
trap '' 3 # to ignore the ^c
clear
echo "\n\n\n\n\n
Enter the db name you wish to connect to \n or quit to exit : \c"
read DB123

dbcheck
}

getdb
There is no substitute to HARDWORK
Arunvijai_4
Honored Contributor

Re: Help Needed for Script

Karthick K S
Frequent Advisor

Re: Help Needed for Script

Hi RAC,

Trap is not working pls help me if u hv example pls tell
RAC_1
Honored Contributor
Solution

Re: Help Needed for Script

change trap command as follows and check.
trap "" 1 2 3 # to ignore trap signals 1 2 3
There is no substitute to HARDWORK
Karthick K S
Frequent Advisor

Re: Help Needed for Script

Thanks RAC,

Trap is working now my script is disabled the CTRL-C but how i should comeout from current telnet session thro' script
Arunvijai_4
Honored Contributor

Re: Help Needed for Script

Hi Karthik,

You need to logout from the shell or kill it's PPID within the script. Take a look at the link which i have posted earlier on how to accomplish this.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Muthukumar_5
Honored Contributor

Re: Help Needed for Script

Yes Simply as,

trap "exit;" 1 2 3 # to ignore trap signals 1 2 3

It will execute exit command on getting signal 1 or 2 or 3.

-Muthu
Easy to suggest when don't know about the problem!
RAC_1
Honored Contributor

Re: Help Needed for Script

You mean to say, when ^c, is pressed, you should get logout?? do it as follows then.
change trap statement as follows.
trap 'echo "logging out";logout' 1 2 3

If you mean, when quit is entered, then it should logout, then do it as follows.

dbcheck()
{
if [ $DB123 = "quit" ]
then
clear
breat #-->modified this.
else
getdb
fi
}
logout #--> modified this.
There is no substitute to HARDWORK
RAC_1
Honored Contributor

Re: Help Needed for Script

You mean to say, when ^c, is pressed, you should get logout?? do it as follows then.
change trap statement as follows.
trap 'echo "logging out";logout' 1 2 3

If you mean, when quit is entered, then it should logout, then do it as follows.

dbcheck()
{
if [ $DB123 = "quit" ]
then
clear
break #-->modified this.
else
getdb
fi
}
logout #--> modified this.
There is no substitute to HARDWORK
Muthukumar_5
Honored Contributor

Re: Help Needed for Script

RAC,

Replied twice. Is it one for new year greetings to karthik. ;)

PS: Not relavent to post.

Typing related with post--->

You can execute a function or command with trap "part" information.

-Muthu



Easy to suggest when don't know about the problem!
Karthick K S
Frequent Advisor

Re: Help Needed for Script

Thanks to all to give good information,

But actually what i need CTRL-C should be disbled(this is working) and also if user quit the database and same time user should comeout from telnet sessions and user should never go to $ prompt
Muthukumar_5
Honored Contributor

Re: Help Needed for Script

May be like,

dbcheck()
{
if [ $DB123 = "quit" ]
then
clear
# Killing that shell
kill -9 $(who -mu | awk '{ print $7;}')
else
getdb
fi
}

Try it out.

-Muthu
Easy to suggest when don't know about the problem!
RAC_1
Honored Contributor

Re: Help Needed for Script

Now I get it. The profile of user or something starts this menu (seperate shell script) So in shell script if user enters "quit", he should also logout from telnet session.

Ok, we do it as follows.
Modify the function as follows.

dbcheck()
{
if [ $DB123 = "quit" ]
then
clear
echo "${DB123}" > $HOME/.some_file
exit 0
else
getdb
fi
}

Also modify the .profile/the script that starts the menu script as follows.

exit_status_of_script=$(< ~/.some_file)
if [[ ${exit_status_of_script} = "quit" ]]
then
exit 0
else
continue
fi
There is no substitute to HARDWORK
Karthick K S
Frequent Advisor

Re: Help Needed for Script

Thankx guys,

Now my script is working fine and once again thanks to all guys.

Happy Christmas and New YEAR