cancel
Showing results for 
Search instead for 
Did you mean: 

Bourne shell script

Avery_1
Advisor

Bourne shell script

Do you know how to slove this script:

write a Bourne shell that will allow a user to specify a number of files to be printed and which email the user with the results of the command. The script should email the user a list of the files that were sent to the printer as well as a list of the files that could not be sent to the printer.

i tried to do this but wont work...please help...
hey
12 REPLIES
Ramkumar Devanathan
Honored Contributor

Re: Bourne shell script

Sophia,

It would be good if you could post out your script so that we may debug it.

- ramd.
HPE Software Rocks!
Avery_1
Advisor

Re: Bourne shell script

if [ $# -eq 0 ]
then
echo "Usage:./printfile directory_name" 1>&2
exit 1
else
cd $1 ls ; (ls | wc -w)
echo "Number of files to be printed: " 1>&2
read fileNo
while [ !$fileNo ]
do
lpr -P[printer]
lpr -m logname
done
fi



i dunno wat to do...quite embarassing to show my script actually
hey
Balaji N
Honored Contributor

Re: Bourne shell script

hi sophia,
is this some kind of a home work u r looking for? :-(



do u have a script already built. if yes, pls post it. we can try to fix it.

hth
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Ramkumar Devanathan
Honored Contributor

Re: Bourne shell script

Hi sophia,

try this for checking if the lpr command returned successfully -

res=`lpr -P $docname`
if [[ $res -ne 0 ]]; then
echo "error occured while printing $docname"
else
echo "successfully printed $docname"
fi

HTH.

- ramd.
HPE Software Rocks!
Ramkumar Devanathan
Honored Contributor

Re: Bourne shell script

Hi sophia,

try this for checking if the lpr command returned successfully -

res=`lpr -P $docname`
if [[ $res -ne 0 ]]; then
echo "error occured while printing $docname"
else
echo "successfully printed $docname"
fi

HTH.

- ramd.
HPE Software Rocks!
Ramkumar Devanathan
Honored Contributor

Re: Bourne shell script

Hi sophia,

try this for checking if the lpr command returned successfully -

res=`lpr -P $docname`
if [[ $res -ne 0 ]]; then
echo "error occured while printing $docname"
else
echo "successfully printed $docname"
fi

HTH.

- ramd.
HPE Software Rocks!
Ramkumar Devanathan
Honored Contributor

Re: Bourne shell script

Oops! That echoed!!!

- ramd.
HPE Software Rocks!
Avery_1
Advisor

Re: Bourne shell script

it says [: -ne:unary operator expected
hey
Ramkumar Devanathan
Honored Contributor

Re: Bourne shell script

hi,

Try the attached script.

call as ./sh.sh

ensure that execute permissions are available. if not, run
chmod +x sh.sh

- ramd.
HPE Software Rocks!
Avery_1
Advisor

Re: Bourne shell script

./sh.sh: Command not found.

Type this:chmod +x sh.sh says

chmod: getting attributes of `sh.sh' : No such file or directory
hey
Ramkumar Devanathan
Honored Contributor

Re: Bourne shell script

Sophia,

I guess you are a newbie to shell programming and also working in unix.

I suggest the following -
- learn to work in linux and how to use the shell - try to run small shell scripts - learn about absolute paths, relative paths, what './' and '../' say, refer to.
- read books on unix shell programming. you will find quite a few if you search in the www
- try out some easy programs which are given in the books above.
- all this will definitely help you to debug your problem.

the script i've given is to be copied onto your machine, in a directory say /tmp.

you may cd /tmp and then run as i'd suggested, or run it from your home directory as
$ /tmp/sh.sh

here are a few links to linux tutorials -

1. http://www.tldp.org/LDP/abs/html/

2. http://steve-parker.org/sh/sh.shtml

3. http://librenix.com/?inode=1774

you can search at google with the keywords

bash programming scripting tutorial

HTH.

- ramd.
HPE Software Rocks!
Avery_1
Advisor

Re: Bourne shell script

yes i'm a newbie...thanks for ur help....really...
hey