Re: Command Line Interface
From: GreyGeek (jkreps_at_neb.rr.com)
Date: Sat, 02 Oct 2004 14:00:01 GMT
Alan Connor wrote:
> On 1 Oct 2004 19:18:11 -0700, saras
> <firstname.lastname@example.org> wrote:
>> I require to write a Command Line Interface in C which should
>> be launched instead of bash shell(Both in case of Telnet
>> sessions and terminal output). This Command Line Interface
>> should accept system commands only for an administrator. In all
>> other cases it should only execute my custom commands. Is there
>> a good place where I could look for some such program(with the
>> source code). Or anyone could suggest how to achieve this. Also
>> how should I supress the bash shell and launch my custom CLI
>> during telnet session initiation/System boot up.
>> Any help on this will be highly appreciated.
> You can do this with bash, by having a script instead of a
> shell listed in /etc/passwd.
> joeuser:x:1006:1006 Joe User
> The script could run in a restricted shell and offer a menu of
> commands to which the user would be limited, and any attempt to
> leave the menu would result in a warning or being logged out.
> Something like:
> # yourscript.sh
> # if they try to kill the script with Ctrl-c and access the
> # shell that way, logout
> trap logout SIGINT
> while true; do
> echo " edit a file"
> echo " browser"
> read num
> case "$num" in
> "1" ) $EDITOR ;;
> "2" ) mozilla ;;
> *) echo "Incorrect entry, try again" ; sleep 2 ; continue ;;
> Be mindful of utilities and applications that offer shell
> escapes and disable them.
That is an exact outlne of a one page bash script I wrote for a SUSE 6.4 box
that was attached to two phones in roll over. The box received tax return
files from the IRS and allowed users with passwords to log into their
account, and either 1) change account password (but not accounts), 2)
download new files 3) download old files, 4) quit. The script was put in
etc/skel so that when the operator added a new account that script was the
login script for that account.
The previous 'solution' was Win98 + WildCat 4.5 running on a P500 Dell box
with 256MB of RAM and two 4GB drives. It crashed often, from once to
several times a day. It couldn't be trusted to run over night or on
weekends because of the crashing. The IT dept had replaced the box several
times, upgraded Win98 with every patch MS had, and consulted with WildCat,
who blamed MS. The IT dept was rapidly pro MS and it was in deparation
that the boss told them to come to me and ask me to set up a Linux
solution. Instead of that P500 + 256MB box which they were using, they
could only 'scrap up' a P75 with 64MB of RAM and two 1GB HDs. I used 1
bash script and two Python scrips, each less than a page long. The python
scripts were the ones that recieved the IRS files and then distributed
them. They were not combined because their functions were needed at
different times. I installed everything but the /home account on hda,
and /home on hdb. During the demo, with the boss and the IT folks standing
around watching, the hdb died. I happend to be logged in as root at the
time, and ReiserFS handled it gracefully, to everyone's amazement! The bad
hdb was quickly replaced with a new one and folks watched as I formtted it
and made it /home, and then created a new account to play with besides
root. To add to that, while I was continuing the app one of the IT boys
asked "what happens if the power goes off?" I reached over and hit the
power button, turning the box off without shutting down. I wanted a few
seconds while folks stood with mouths agap, and then retored power.
ReiserFS picked up the abend and replayed some journal entries, restoring
the system to pristine condition in just a few seconds.
When the boss saw that he told the IT folks to stop messing around and give
me anything I wanted. I told them the P75 + 64MB of RAM and two 1GB HDs
were just fine. I was done. The system was setup. All I needed to do was
show the operator what the two phython scripts expected her to do.
The gal who was responsible for running the system was concerned that Linux
would be different and harder to use than Windows, which she was familiar
with. I had set up the SUSE box to run KDE 1.1, the latest version at the
time, and after she played with it for a while she remarked "It's just like
Windows, really." She had no trouble.
My Linux version of a BBS ran for 36months/24/7 without a single crash,
before the boss outsourced that function and reassigned the gal to being
the Lotus Notes administrator. Which she is very good at!