nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

couple of noob questions

This is a discussion on couple of noob questions within the Shell scripting forums, part of the Development/Scripting category; Is it best to wright menu driven script all in one file of link it to different scripts If linking ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 04-03-2006, 11:09 PM
Member
User
 
Join Date: Mar 2006
Posts: 35
Rep Power: 0
sparky
Default couple of noob questions

Is it best to wright menu driven script all in one file of link it to different scripts
If linking how do that ?

Is there away when a script exits to leave you in the directory the script it self was last in b4 exit instead of returning you back to to dir you where in when you started script.
ie..
start script in \home
script runs and change dir a few time finishing in \home\whatever
script exits and your shell returns prompt back in \home
how do get prompt back so you are still in \home\whatever

Is there away to kill processes without the pid No
ie process name
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-04-2006, 02:04 AM
sweta's Avatar
Contributors
User
 
Join Date: Feb 2005
Location: New Delhi
My distro: Suse, RHEL, Vista
Posts: 154
Rep Power: 4
sweta will become famous soon enough
Default Re: couple of noob questions

Quote:
Originally Posted by sparky
Is there away to kill processes without the pid No
ie process name
Use killall command to kill processes by name, for example killall firefox process:
Code:
killall -9 firefox
__________________
Friends - v-nessa - missyAdmin - LinuxChix
Reply With Quote
  #3 (permalink)  
Old 04-04-2006, 11:30 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

Quote:
Is it best to wright menu driven script all in one file of link it to different scripts
If linking how do that ?
If your shell script is very big, divide it into function and call function from main script.
function.sh
Code:
function a(){
  echo "I am a()"
}

function b(){
  echo "I am b()"
}
script.sh
Code:
#!/bin/bash
source function.sh
a
b
Quote:
Is there away when a script exits to leave you in the directory the script it self was last in b4 exit instead of returning you back to to dir you where in when you started script.
ie..
start script in \home
script runs and change dir a few time finishing in \home\whatever
script exits and your shell returns prompt back in \home
how do get prompt back so you are still in \home\whatever
Sorry but I’m not really getting your point… could you more specific?
Reply With Quote
  #4 (permalink)  
Old 04-06-2006, 04:30 AM
Member
User
 
Join Date: Mar 2006
Posts: 35
Rep Power: 0
sparky
Default

I was just playing about right silly little short cut type scripts to help manage out server
heres two silly examples that did not work
Code:
echo -e "changing directory"
cd /var/www/html
ls | more
Was hoping it would leave me in that dir so i could then choose which website i wanted to edit..
But when script exits i u return to dir where u started script from.

Then i wrote 3 little scripts for TeamSpeak one checks status one stops but the 3rd which should restarted ts did not work.
The first 2 are all run as root and they work fine but the 3rd changes users and does not work..

Code:
cd /home/ts/tss2_rc2
su ts
./teamspeak2-server_startscript start
The others are the same except with out su ts

Just some silly little thing i was playing about with not inportant just help you learn and move on to biggger things
Reply With Quote
  #5 (permalink)  
Old 04-08-2006, 10:36 AM
tom tom is offline
Contributors
User
 
Join Date: Jun 2005
Location: London, UK
Posts: 213
Rep Power: 4
tom is on a distinguished road
Default

Hmm...

I just tested your current directory problem in script. You are right script does not remember changed directory location

May be some one here should able to solve your problem
Reply With Quote
  #6 (permalink)  
Old 04-08-2006, 10:33 PM
Member
User
 
Join Date: Mar 2006
Posts: 35
Rep Power: 0
sparky
Default

I Think i no why but i wonder what the way round it is
When you open terminal that is for example your login shell, when you run a script it opens a new shell and your login goes into hibernation if you like when script finishes that shell shuts and put's you back in login shell
That what i think happens i am probably way off
Reply With Quote
  #7 (permalink)  
Old 04-09-2006, 02:27 PM
Member
User
 
Join Date: Mar 2006
Posts: 35
Rep Power: 0
sparky
Default

found one way round it, run script using . command causes the script to get excuted using the same shell
ie run you script
./myscript opens new shell
.myscript cause script to run in current shell

Reply With Quote
  #8 (permalink)  
Old 04-09-2006, 05:09 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

When a child process is created (your script), it copy of its variables and current directory. So the child (your script) can change these values all it wants but the changes won't affect the parent shell, since the child is changing a copy of the original data.

As you said use
Code:
.  scriptname
It Read and execute commands from scriptname in the current shell environment and return the exit status of the last command executed from script.
Reply With Quote
  #9 (permalink)  
Old 04-09-2006, 05:22 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

sparky thanks for sharing back your solution with us

Monk nice clarification about . scriptname command
__________________
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
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Real Interview Questions Ashish Pathak The Hangout 15 10-20-2008 11:54 PM
Linux Administrator Interview Questions jhn_daz@yahoo.com Linux software 4 08-19-2008 10:53 AM
Complete NOOB need help gham Shell scripting 0 06-04-2007 10:56 PM
RHCE sample questions require puppen Linux software 3 04-13-2006 07:36 PM
few quick perl questions raj All about FreeBSD/OpenBSD/NetBSD 1 06-30-2005 01:27 AM


All times are GMT +5.5. The time now is 05:52 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36