error running shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error running shell script
# 15  
Old 05-12-2010
Quote:
for i in `cat diffs.txt`
do
printer="$(awk -F: '{ print $1 }' | cut -c 11-18 diffs.txt)"
echo $printer
done
This section of script contains many errors and always leaves $printer blank.

What is it intended to do?
# 16  
Old 05-13-2010
running the script with "ksh -x resync-printers.ksh" from the command line not the same????

---------- Post updated at 07:36 ---------- Previous update was at 07:29 ----------

It cuts the printer name i require, for me to delete and recreate it if necessary
here is the diffs.txt file

Quote:
more diffs.txt
device for 0117bd1: lpd://172.25.29.60:515
device for 2201bl7: socket://172.25.11.170:9100
device for 5001bl1: lpd://172.25.11.203:515
If there are errors, any suggestions as to how i can improve it???

---------- Post updated at 09:21 ---------- Previous update was at 07:36 ----------

Can someone please assist me.?Smilie

---------- Post updated at 09:37 ---------- Previous update was at 09:21 ----------

Quote:
Originally Posted by zaxxon
As already stated in your other thread for this script, use set -x and set +x for debugging. Place it in this case into your stuck function maybe.
but i am running my script with ksh -x resync-printers.ksh
# 17  
Old 05-13-2010
Quote:
Originally Posted by ggoliath
---------- Post updated at 09:37 ---------- Previous update was at 09:21 ----------

[/COLOR]
but i am running my script with ksh -x resync-printers.ksh
The -x option specified at the command level (has you did) or inside the script (at main level) has no effect inside functions.
If you want to debug a function, add the set -x command in the function body.

Jean-Pierre.
# 18  
Old 05-13-2010
Quote:
Originally Posted by aigles
The -x option specified at the command level (has you did) or inside the script (at main level) has no effect inside functions.
If you want to debug a function, add the set -x command in the function body.

Jean-Pierre.
Where in the function
itried at the beginning of the function but receive a error
Code:
+ f_Create
psset: Unknown or ambiguous option `-x'.
psset: Try `--help' for more information.
         Adding printers !!!!
Enter Printer Name: 0117bd1



---------- Post updated at 11:06 ---------- Previous update was at 09:56 ----------

The pressure is mounting, i need some help.
the script just not seem to continue after entering the printer.It stays hung.Any assistance will be highly appreciated.
i have entered the set -x at the start of the function but it does not give me any joy
here is the function i am trying to execute
Code:
f_Create()
{
set -x
  if [ -z "$printer" ]; then
         echo "\n\t $printer does not exists"
       return 1
    else
       for P in $printer; do
        echo "\n\t Adding printers !!!!"
    echo "Enter $Printer Name: \c"
    read printer
    echo "Enter IP Address  : \c"
    read ip
    echo "Enter Location    : \c"
    read loc
    echo "Enter Description : \c"
    read desc
    echo "Enter Filter      : \c"
    read filt
    echo "Enter Port        : \c"
    read port
    echo "Enter Driver      : \c"
    read driv
    $BIN/lpadmin -p "$printer" -E -D "$desc" -L "$loc" -i /u1/cups/mac/"$filt"_fi
lter -v "$driv"://"$ip":"$port"
    done
    echo "\n\t Printer $printer created"
  fi
}

# 19  
Old 05-13-2010
Code:
for i in `cat diffs.txt`
do
printer="$(awk -F: '{ print $1 }' | cut -c 11-18 diffs.txt)"
echo $printer
done

Back to the beginning of the script. Correction to my previous post after trying a different shell and using your sample data.
Code:
device for 0117bd1: lpd://172.25.29.60:515
device for 2201bl7: socket://172.25.11.170:9100
device for 5001bl1: lpd://172.25.11.203:515

The output is twelve identical lines:
Code:
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1

The reason there are 12 lines is because $i contains the entire contents of diffs.txt without the line terminators. There are twelve distinct space-separated elements. The variable $i is not referred to at all in the script so all that happens is the "printer=" line is executed 12 times. I cannot explain how the "printer=" line outputs anything but when inside a shell script it does.

Code:
Anyway the "for" loop is not required or desirable.
If we remove the loop completely and make sure that awk has a filename parameter, it now works:

printer="$(awk -F: '{ print $1 }' diffs.txt | cut -c 11-18)"
echo $printer

0117bd1 2201bl7 5001bl1

Okay, we now have the (unchanged) situation where $printer contains 3 printer names. This is not desirable when we look at the contents of f_Create.

Suggest you change the "printer=" line above to use a different variable name (e.g. "printer_list="), then look at where you want a list against where you want a single printer.

The f_Create function contains "read printer". This overwrites the variable $printer. The "read printer" line is not required - it is probably what is hanging the script because the input channel is already tied up with the "for" loop.
Further correction: The shell "read" statements conflict with the "for" loop. I think this script needs a redesign.


Footnote. To answer your earlier question it would be possible to automate the whole process but only if your diffs.txt file contains all the information in (which it does not) in a suitably delimeted format.

Last edited by methyl; 05-13-2010 at 08:26 PM.. Reason: Futher correction
# 20  
Old 05-14-2010
Thanks methyl..
Your input has been of great help...I have made the changes as you suggested.
I have changed the create function by removing the read $printer
The function now does create my printers from the #printer_list EXAMPLES
Code:
+ f_Create
+ [ -z  0117bd1
 2201bl7
 5001bl1 ]
+ echo \n\t Adding printers !!!!
         Adding printers !!!!
+ /usr/lbin//lpadmin -p 0117bd1 -E -D  -L  -i /u1/cups/mac/_filter -v ://:
lpadmin: No such file or directory
+ echo \n\t Adding printers !!!!
         Adding printers !!!!
+ /usr/lbin//lpadmin -p 2201bl7 -E -D  -L  -i /u1/cups/mac/_filter -v ://:
lpadmin: No such file or directory
+ echo \n\t Adding printers !!!!
         Adding printers !!!!
+ /usr/lbin//lpadmin -p 5001bl1 -E -D  -L  -i /u1/cups/mac/_filter -v ://:
lpadmin: No such file or directory
+ echo \n\t Printer  created
         Printer  created

but without the required parameters.
[code]
lpstat -v 5001bl1
device for 5001bl1: ///dev/null
[code]

The driver=lpd or socket,Ip address,port=515 or 9100 are vital to create the printers...
I did some research and found something like this
Code:
while IFS=":" read printer driver IP port

Can it work from this????????Smilie

---------- Post updated at 14:08 ---------- Previous update was at 08:27 ----------

Must be a long weekend??????
asisstance will be highly appreciated.Smilie
# 21  
Old 05-14-2010
Quote:
/usr/lbin//lpadmin -p 0117bd1 -E -D -L -i /u1/cups/mac/_filter -v ://:
lpadmin: No such file or directory
The error message are relevant. Perhaps /u1/cups/mac/_filter is missing ?



While in the loop within f_Create you could use grep to interrogate the diffs.txt file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error while running Procedure in shell script

Hi All, I am running the below proc in unix by connecting through sqlplus and the procedure is completing successfully. But when i am trying to run through shell scripting by using function. I am getting the error as follows. Please guide me where I am going wrong. #!/bin/sh opera () {... (6 Replies)
Discussion started by: bhas85
6 Replies

2. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

3. Shell Programming and Scripting

Changing shell from a script and running something from the new shell

Hi We use "tcsh" shell . We do the following steps manually: > exec ssh-agent zsh > python "heloo.py" (in the zsh shell) I am trying to do the steps above from a shell script This is what I have so far echo "Executing " exec ssh-agent zsh python "hello.py" exit 0 Problem is... (5 Replies)
Discussion started by: heman82
5 Replies

4. Solaris

Error during running sqlplus command from shell script in Solaris

I am using following code to connect to oracle database from solaris shell script. which will try thrice to connect the database ...at the 4rth atempt it will exir=t. count=0 while ; do sqlplus -s $usrname/$password@dbSID <<-EOF | tee $logfile WHENEVER OSERROR EXIT 9; WHENEVER SQLERROR... (4 Replies)
Discussion started by: millan
4 Replies

5. Shell Programming and Scripting

Launcher Error: while running shell script

Hi Experts, I have a shell script which used to take oracle database backup, which is scheduled in a tidal scheduling tool. however it is throwing an error while triggering the job and getting below error in the log file. "Launcher Error: This is an internal function" shell script is... (1 Reply)
Discussion started by: UnniVKN
1 Replies

6. Shell Programming and Scripting

Shell script running command in different shell

Hi All, Is there any way where we can run few commands with different shell in a shell script ? Let's have an example below, My first line in script reads below, #!/bin/sh However due to some limitation of "/bin/sh" shell I wanted to use "/bin/bash" while executing few... (9 Replies)
Discussion started by: gr8_usk
9 Replies

7. Shell Programming and Scripting

`(' unexpected error when running a shell script in AIX

Hi, We are moving from linux to AIX servers, and as a result testing our scripts on the new platform. When I run one of our scripts, I get the following error message: ./branchDataUpdate.sh: syntax error at line 21 : `(' unexpected Following is an extract from the script: ...... ........ (1 Reply)
Discussion started by: dawgfather80
1 Replies

8. Shell Programming and Scripting

Error while running as shell script

Storage_Unit=`du -h /var/spool/cron/root|awk '{print $1}'|sed -e "s/^.*\(.\)$/\1/"` If then Size=`du -h /var/spool/cron/root|awk '{print $1}'|sed 's/.\{1\}$//'` for Size_rounded_number in $(printf %.0f $Size); do ROUNDED_Size=$Size_rounded_number done if #setting a threshold of say... (1 Reply)
Discussion started by: proactiveaditya
1 Replies

9. Solaris

Running from Shell Vs running from RC script

Hi, i have a script which need to do behave differently when run as a startup process from init.d/ rc2.d script and when run manually from shell. How do i distinguish whether my script is run by init process or by shell?? Will the command /proc/$$/psinfo | grep "myscript" work well???... (2 Replies)
Discussion started by: vickylife
2 Replies

10. Shell Programming and Scripting

error in running shell script in cron

#!/bin/bash CLASSPATH=. #CLASSPATH=${CLASSPATH}:${INSTALL_PATH}home/squidlog/CopyFile.java CLASSPATH=${CLASSPATH}:${INSTALL_PATH}usr/java/latest/lib/*.jar javac CopyFile.java echo "CLASSPATH=$CLASSPATH" #home/wbiadmin/JRE1.4.2/j2re1.4.2_15/bin/java CopyFile /usr/bin/java... (3 Replies)
Discussion started by: sari
3 Replies
Login or Register to Ask a Question