shell script queries: $home; broadcast ping


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script queries: $home; broadcast ping
# 1  
Old 08-28-2002
Data shell script queries: $home; broadcast ping

Dear all,

This is the Bionic Fysh again. I have two quick questions:

1- when writing shell scripts, how does one allow the tilda ~ into the script ?
e.g
ls ~;
ls ~me;
user=you;
ls ~$user (N.B I think that for this one you need: ls `~$user`)

2- In FreeBSD 4.0, I would like for a normal (wheel) user to ping
by default, only the root can ping. And I would like to send a broadcast ping (like ping -b in linux) to a subnet.
e.g ping -b 192.168.1.0


Many thanks in advance,


Da Bionic 1
;-)
# 2  
Old 08-28-2002
I'm not completely sure what you mean. The tilde should work find just as is:

Code:
ls ~      # lists your home directory
ls ~me    # looks for a directory called ~me
          # if me is your username, also lists your home dir
user=you  #
ls ~$user # will try to list the home directory of
          # someone with a login name of 'you'

Not sure about the second question...
# 3  
Old 08-28-2002
Lightbulb

1.'~' in the shell

ls ~ # lists your home directory
ls ~me # will try to list the home directory of someone with a login name of 'me'
user=you
ls ~$user # will try to list the home directory of someone with a login name of 'you'
ls ~/MyDir # will try to list the 'MyDir' directory (or file) of my $HOME directory
ls ~root/bin # will list the 'bin' directory of '/' (becouse '/' is $HOME directory for the root)

PS:
in all the constructions '~' have to be very first character to get proper shell expansion
look at the 'Directory Substitution' under man for shell


2. ping question

Find location of the ping command ('which ping' or 'type ping' depending on your shell).
Examine directory attributes of the 'ping' location ( 'ls -l directoryname`)
If this directory is not readable or not executable by the 'world',
then copy ping to the common location ( 'usr/bin' )
# 4  
Old 08-29-2002
Data shell scripting...

Hi guys,

very sorry but I tried your recommendations, and this is what I get:

in script: myscript

ls ~
ls ~root
user=you
ls ~$user

OUTPUT
~: Ce fichier ou ce rÚpertoire n'existe pas
~: This file or directory does not exit

~root: Ce fichier ou ce rÚpertoire n'existe pas
~:root: This file or directory does not exit

~you: Ce fichier ou ce rÚpertoire n'existe pas
~you: This file or directory does not exit


Thanks for any pointers


N.B thanks for the ping trick... now my users can ping without doing su - ...!
does anyone know how to do a 'broadcast ping'
e.g ping 192.168.1.0

returns something like:
found 192.168.1.1
found 192.168.1.2
found 192.168.1.3
found 192.168.1.4
etc....

Da Bionic 1
:-)
# 5  
Old 08-29-2002
I'm not sure what's wrong.. I use Sco, but FreeBSD also uses the "~" to point to your home directory..

Until someone can help you out more or you figure out the problem, try this:

ls $HOME
user=xxx
ls $HOME/../$user

The first line is equivalent to ls ~

The last line will attempt to list some other user's directory, assuming all user directories are listed within the same directory.

Of course, if your account is root, then all other users will probably be somewhere beneath you, e.g. like /usr/home/xxx, so you can use ls /usr/home/$user
# 6  
Old 08-30-2002
Lightbulb shell scripting...

Dear all,

Thanks so much for the feedback.
I have tried the following:

vi new

ls $HOME
ls ~
ls ~toto

they all respond accordingly

however:

user=toto
ls ~$user

it returns: can't ls to ~toto (???)


so the script can find ~sos10
and can view the variable user as a character variable
...
but cannot work with both...

I hear that this is not possible in bash...
and may be possible in csh, tcsh, or maybe sh

but I always thought that when you do sh script
it would run it in pure sh ...?


cheers again for any comments

N.B please try this exactly:
user=toto
echo~$user


bionic fysh

Last edited by bionicfysh; 08-30-2002 at 11:02 AM..
# 7  
Old 08-30-2002
Re: shell scripting...

Quote:
Originally posted by bionicfysh

however:

user=toto
ls ~$user
The shell expands stuff like ~toto into a directory name early in its processing of a command line. And it expand $user fairly late.

Try this:

eval "ls ~$user"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue on executing db2 queries through shell script

hi i am trying to execute db2 queries through shell script. it's working fine but for few queries is not working ( those queries are taking time so the script is not waiting to get the complete the execution of that query ) could you please any one help me on this is there any wait... (1 Reply)
Discussion started by: bhaskar v
1 Replies

2. Shell Programming and Scripting

run sql queries from UNIX shell script.

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX? :confused: (1 Reply)
Discussion started by: 24ajay
1 Replies

3. Linux

How to store count of multiple queries in variables in a shell script?

how to store the count of queries in variables inside a filein shell script my output : filename ------- variable1=result from 1st query variable2=result from 2nd query . . . . (3 Replies)
Discussion started by: sanvel
3 Replies

4. Shell Programming and Scripting

Executing set of sql queries from shell script

Hi All, I tried executing set of queries from shell script but not able to capture the input query in the log file. The code looks something similar to below sqlplus user/pwd@dbname << EOF > output.log $(<inputfile.txt) EOF The above code is capturing the output of queries into... (9 Replies)
Discussion started by: loggedin.ksh
9 Replies

5. Shell Programming and Scripting

Shell script to give broadcast and network address

Hello, I am running a post script in autoyast where I am trying to set the broadcast and network address. I have the ip address and netmask already (reading from a file).. I saw the post from fpmurphy but it is using ksh which isn't an option in autoyast. Thanks in advance! (3 Replies)
Discussion started by: bloodclot
3 Replies

6. Shell Programming and Scripting

Nested SQL queries within Shell script

Hi, Would someone know if I can fire nested sql queries in a shell script? Basically what I am trying to do is as follows: my_sql=$(sqlplus -s /nolog<<EOF|sed -e "s/Connected. *//g" connect... (2 Replies)
Discussion started by: shrutihardas
2 Replies

7. Shell Programming and Scripting

How to extract queries using UNIX shell script?

Hi, I have an input file which have many lines,from which i need to extract only the complete sql statements and write this alone to an output file. please help us in this. Regards Meva (7 Replies)
Discussion started by: meva
7 Replies

8. Shell Programming and Scripting

Multiple MySql queries in shell script?

Hi guys, i know how to run a single query using mysql embedded in a shell script as follows: `mysql -umyuser -pmypass --host myhost database<<SQL ${query}; quit SQL` However, how would i be able to run several queries within the same connection? The reason for this is i am creating... (3 Replies)
Discussion started by: muay_tb
3 Replies

9. UNIX for Dummies Questions & Answers

shell script for sql queries

Hi All, I have written 4 sql queries . Now I want to write one SHELL SCRIPTING program for all these queries... i.e 1.select * from head; 2. select * from detail; 3. delete from head; 4. delete from detail; Please let me know how to write a shell script... Thank you (1 Reply)
Discussion started by: user71408
1 Replies

10. UNIX for Dummies Questions & Answers

Sh Shell Script executing remote SQL queries

Hi there folks, I am trying to execute remote sql queries on an Oracle server. I would like to save the result of the executed sql queries on a text file, and send that text file as an attachment to an email address. Could anyone give me an idea on how the above could be achieved? Any help... (2 Replies)
Discussion started by: Javed
2 Replies
Login or Register to Ask a Question