This is a discussion on changing dir within the Shell scripting forums, part of the Development/Scripting category; I am a linux noob migrated from windows anout a month ago and am lovng my fedora 5 set up. ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
I am a linux noob migrated from windows anout a month ago and am lovng my fedora 5 set up.
Any ways i look after a few linux servers some of which are gaming servers i decided to have a go at writing a script to start and stop servers which works fine, a menu for ip port max players etc then it starts the server (very pleased with my self i then decided to try and take it a step further when i log in via ssh i want excute myscript straight away with out navagting to each server i have a menu options ask me which server i would like to manage then i need it to cd to dir of my chioce but i can not seem to figure out how to make cd command work. Code:
if [ $choice ==0 ] ; then CANT FIGURE OUT /home/cssource elif [ $choice ==1] ; then cd /home/server01 etc etc |
| Sponsored Links | ||
|
|
|
|||
|
You are using == operator which is for string comparison and not for number comparison. Use –eq for equal to. In short,
Code:
if [ $choice -eq 0 ]; then
cd /home/0
elif [ $choice -eq 1 ]; then
cd /home/1
else
echo "Etc etc"
fi
|
|
|||
|
Thanks for such a quick reply i tried that and no luck may be i am missing something here as i said i am a complete noob
I ll post my script Code:
echo css server management--Please choose a server. echo cssource [0] echo cssource [1] echo cssource [2] echo cssource [3] echo cssource [4] echo cssource [5] echo cssource [6] echo cssource [7] echo cssource [8] echo cssource [9] echo cssource [10] echo cssource [11] echo cssource [12] #store vars read choice if [ $choice -eq 0 ] ; then cd /home/sparky/backup elif [ $choice -eq 1] ; then cd /home/server01 elif [ $choice -eq 2] ; then cd /home/server02 elif [ $choice -eq 3] ; then cd /home/server03 elif [ $choice -eq 4] ; then cd /home/server04 elif [ $choice -eq 5] ; then cd /home/server05 elif [ $choice -eq 6] ; then cd /home/server06 elif [ $choice -eq 7] ; then cd /home/server07 elif [ $choice -eq 8] ; then cd /home/server08 elif [ $choice -eq 9] ; then cd /home/server09 elif [ $choice -eq 10] ; then cd /home/server10 elif [ $choice -eq 11] ; then cd /home/server11 elif [ $choice -eq 12] ; then cd /home/server12 else exit fi #server options. echo please fill in these 3 questions and ill start your server #Enter port echo -n Please enter port you wish to use : read port #tick echo -n Please enter server tick rate : read tick #Max players echo -n Please enter max players : read players ./srcds_run -game cstrike -port $port +ip194.105.134.151 +maxplayers $players -tickrate $tick +map de_dust +exec server.cfg -autoupdate & ./css: line 28: /home/sparky/backup: is a directory Thanks |
|
|||
|
Hmm
What is output of command: Code:
ls -ld /home/sparky/backup Code:
mkdir -p /home/sparky/backup |
|
|||
|
All the dirs exist just can t get script to swap to them
out put of ls Code:
[sparky@localhost ~]$ ls -ld /home/sparky/backup drwxrwxr-x 2 sparky sparky 4096 Mar 27 20:55 /home/sparky/backup |
|
|||
|
Thanks for all the speedy help so far getting there now it will change if i chosse option 0 but if i choose 1 to 12 i get
the code is as above but with the first if all on one line now Code:
css server management--Please choose a server. cssource [0] cssource [1] cssource [2] cssource [3] cssource [4] cssource [5] cssource [6] cssource [7] cssource [8] cssource [9] cssource [10] cssource [11] cssource [12] 12 ./css: line 28: [: missing `]' ./css: line 29: [: missing `]' ./css: line 30: [: missing `]' ./css: line 31: [: missing `]' ./css: line 32: [: missing `]' ./css: line 33: [: missing `]' ./css: line 34: [: missing `]' ./css: line 35: [: missing `]' ./css: line 36: [: missing `]' ./css: line 37: [: missing `]' ./css: line 38: [: missing `]' ./css: line 39: [: missing `]' |
|
||||
|
Ya here you go; following code should work...
Code:
echo css server management--Please choose a server. echo cssource [0] echo cssource [1] echo cssource [2] echo cssource [3] echo cssource [4] echo cssource [5] echo cssource [6] echo cssource [7] echo cssource [8] echo cssource [9] echo cssource [10] echo cssource [11] echo cssource [12] #store vars read choice if [ $choice -eq 0 ] ; then cd /home/sparky/backup elif [ $choice -eq 1 ] ; then cd /home/server01 elif [ $choice -eq 2 ] ; then cd /home/server02 elif [ $choice -eq 3 ] ; then cd /home/server03 elif [ $choice -eq 4 ] ; then cd /home/server04 elif [ $choice -eq 5 ] ; then cd /home/server05 elif [ $choice -eq 6 ] ; then cd /home/server06 elif [ $choice -eq 7 ] ; then cd /home/server07 elif [ $choice -eq 8 ] ; then cd /home/server08 elif [ $choice -eq 9 ] ; then cd /home/server09 elif [ $choice -eq 10 ] ; then cd /home/server10 elif [ $choice -eq 11 ] ; then cd /home/server11 elif [ $choice -eq 12 ] ; then cd /home/server12 else exit fi #server options. echo please fill in these 3 questions and ill start your server #Enter port echo -n Please enter port you wish to use : read port #tick echo -n Please enter server tick rate : read tick #Max players echo -n Please enter max players : read players ./srcds_run -game cstrike -port $port +ip194.105.134.151 +maxplayers $players -tickrate $tick +map de_dust +exec server.cfg -autoupdate & Code:
elif [ $choice -eq 1] ; then cd /home/server01 Code:
elif [ $choice -eq 1 ] ; then cd /home/server01
__________________
Rocky Jr. You may have my body & soul, but you will never touch my pride! If you have knowledge, let others light their candles at it. Certified to work on HP-UX / Sun Solaris / RedHat |
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| changing to SU in cronjob | xpy | Shell scripting | 0 | 04-16-2008 02:29 PM |
| Bonding mode not changing | bdptcob | Linux software | 3 | 06-05-2007 11:29 AM |
| Changing password at first login. Linux | sbhupathireddy | Linux software | 1 | 07-05-2006 01:29 PM |
| changing desktop to kde | All about FreeBSD/OpenBSD/NetBSD | 1 | 01-11-2006 11:47 PM | |
| linux changing run level | Linux software | 1 | 01-10-2006 07:25 PM | |