nixCraft Linux Forum

nixCraft

Linux / UNIX 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

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-04-2006, 10:09 PM
Member
User
 
Join Date: Mar 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
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
  #2 (permalink)  
Old 04-04-2006, 01:04 AM
sweta's Avatar
Contributors
User
 
Join Date: Feb 2005
Location: New Delhi
OS: Suse, RHEL, Vista
Posts: 199
Thanks: 12
Thanked 9 Times in 9 Posts
Rep Power: 7
sweta has a spectacular aura about sweta has a spectacular aura about
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
__________________
Reply With Quote
  #3 (permalink)  
Old 04-04-2006, 10:30 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
OS: Debian GNU/Linux
Posts: 506
Thanks: 0
Thanked 8 Times in 6 Posts
Rep Power: 7
monk has a spectacular aura about monk has a spectacular aura about
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 06-04-2006, 03:30 AM
Member
User
 
Join Date: Mar 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
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 08-04-2006, 09:36 AM
tom tom is offline
Contributors
User
 
Join Date: Jun 2005
Location: London, UK
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 5
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 08-04-2006, 09:33 PM
Member
User
 
Join Date: Mar 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
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 09-04-2006, 01:27 PM
Member
User
 
Join Date: Mar 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
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 09-04-2006, 04:09 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
OS: Debian GNU/Linux
Posts: 506
Thanks: 0
Thanked 8 Times in 6 Posts
Rep Power: 7
monk has a spectacular aura about monk has a spectacular aura about
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 09-04-2006, 04:22 PM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 705
Thanks: 15
Thanked 19 Times in 18 Posts
Rep Power: 10
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
Default

sparky thanks for sharing back your solution with us

Monk nice clarification about . scriptname command
__________________
Rocky Jr.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote
Reply


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 Off


Similar Threads

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


All times are GMT +5.5. The time now is 10:34 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 37 38