Bash Shell Script Problems - Advice Needed

Bash Shell Script Problems - Advice Needed

Post by Nick Hepplest » Wed, 31 Oct 2001 18:52:01



I've developed the following script which is meant to retrieve xml
data from a webpage, but i need any '&' to be changed to '&'. I'm
running this through an awk command but the output either never gets
written to the file (i.e. the file is created and is blank) or the
file never gets created.

any help would be greatly appreciated (for starters, is the awk
command correct??)

Thanks, Nick

************************************************************************

#!/bin/sh

# Get IT reseller XML news feed
(lynx -source http://www.cw360asp.com/News_Feeds/Extraction.asp?feed=Reseller_Break...)

Quote:> resellernews.tmp

# Change all of the & characters to read as &, this will stop the
XML parsing routines from falling over
awk '{ gsub(/&/, "&"); print $0 > "resellernews.xml"}'
resellernews.tmp

# destroy .tmp and .new files (we only need the .xml and .old files)
rm resellernews.tmp

 
 
 

Bash Shell Script Problems - Advice Needed

Post by Sebastian Han » Wed, 31 Oct 2001 19:43:13



> #!/bin/sh

> # Get IT reseller XML news feed
> (lynx -source http://www.cw360asp.com/News_Feeds/Extraction.asp?feed=Reseller_Break...)
> > resellernews.tmp

> # Change all of the & characters to read as &, this will stop the
> XML parsing routines from falling over
> awk '{ gsub(/&/, "&"); print $0 > "resellernews.xml"}'
> resellernews.tmp

> # destroy .tmp and .new files (we only need the .xml and .old files)
> rm resellernews.tmp

Assuming the awk command and the filename are on one line.

The gsub function isn't supported by all implementations of awk.
Does it give you a syntax error?

If it doesn't, the problem could be the 'print $0 > "resellernews.xml"'
statement. AFAIK, awk isn't supposed to reuse the filehandle once the
output file is opened, but try replacing the '>' with '>>'.
Better yet, don't put the redirection in the awk-script.
Do it like this, instead:

awk '{ gsub(/&/, "&"); print $0}' resellernews.tmp >
resellernews.xml

Or use something else altogether. You don't really need awk for this.
Here's how you do it with sed:

sed -e 's/&/&amp;/g' < resellernews.tmp > resellernews.xml

HTH
--
Sebastian Hans >< My words are my own.
For every action, there is an equal and opposite malfunction. -- Murphy
This mail was created with VIM 5.6 -- no proprietary products used.

 
 
 

Bash Shell Script Problems - Advice Needed

Post by Floyd Davidso » Thu, 01 Nov 2001 02:54:22



>I've developed the following script which is meant to retrieve xml
>data from a webpage, but i need any '&' to be changed to '&amp;'. I'm
>running this through an awk command but the output either never gets
>written to the file (i.e. the file is created and is blank) or the
>file never gets created.

>any help would be greatly appreciated (for starters, is the awk
>command correct??)

>Thanks, Nick

Perhaps awk is not the best tool.  Try sed:

   sed -e 's/&/&amp/g' < infile > outfile

Quote:>************************************************************************

>#!/bin/sh

># Get IT reseller XML news feed
>(lynx -source http://www.cw360asp.com/News_Feeds/Extraction.asp?feed=Reseller_Break...)
>> resellernews.tmp

># Change all of the & characters to read as &amp;, this will stop the
>XML parsing routines from falling over
>awk '{ gsub(/&/, "&amp;"); print $0 > "resellernews.xml"}'
>resellernews.tmp

># destroy .tmp and .new files (we only need the .xml and .old files)
>rm resellernews.tmp

--
Floyd L. Davidson         <http://www.ptialaska.net/~floyd>

 
 
 

Bash Shell Script Problems - Advice Needed

Post by Nick Hepplest » Fri, 02 Nov 2001 19:24:19


Thanks for your help guys. I've tried the sed command and it works
fine - from the command prompt... When i place it into a script the
'new' file is created, but with no data.

To get my head around where the problem is, i now have 2 scripts, one
retrieves the xml data (via lynx) and simply dumps the output to file.
a second script then  runs the sed/awk command. when i run these
scripts independently of each other, i.e. from the command prompt with
a pause of ~10 seconds, i have no problems, when i call the second
script form the first (in a feeble attempt at automation...) the .xml
files have 0 bytes of data...

Is there a 'sleep' method that i can call to halt the processing for
2-3 seconds before running the sed/awk command??

Note: The script will run on a Sun Cobalt Linux 2.2 box (i believe its
a sun tailored distro...)

thanks for your help on this matter, Nick


> I've developed the following script which is meant to retrieve xml
> data from a webpage, but i need any '&' to be changed to '&amp;'. I'm
> running this through an awk command but the output either never gets
> written to the file (i.e. the file is created and is blank) or the
> file never gets created.

> any help would be greatly appreciated (for starters, is the awk
> command correct??)

> Thanks, Nick

> ************************************************************************

> #!/bin/sh

> # Get IT reseller XML news feed
> (lynx -source http://www.cw360asp.com/News_Feeds/Extraction.asp?feed=Reseller_Break...)
> > resellernews.tmp

> # Change all of the & characters to read as &amp;, this will stop the
> XML parsing routines from falling over
> awk '{ gsub(/&/, "&amp;"); print $0 > "resellernews.xml"}'
> resellernews.tmp

> # destroy .tmp and .new files (we only need the .xml and .old files)
> rm resellernews.tmp

 
 
 

Bash Shell Script Problems - Advice Needed

Post by Floyd Davidso » Sat, 03 Nov 2001 02:16:20



>Thanks for your help guys. I've tried the sed command and it works
>fine - from the command prompt... When i place it into a script the
>'new' file is created, but with no data.

Without seeing exect (cut and paste, not retyped) copies of the your
scripts it is somewhat difficult to determine what you have.

>To get my head around where the problem is, i now have 2 scripts, one
>retrieves the xml data (via lynx) and simply dumps the output to file.
>a second script then  runs the sed/awk command. when i run these
>scripts independently of each other, i.e. from the command prompt with
>a pause of ~10 seconds, i have no problems, when i call the second
>script form the first (in a feeble attempt at automation...) the .xml
>files have 0 bytes of data...

>Is there a 'sleep' method that i can call to halt the processing for
>2-3 seconds before running the sed/awk command??

>Note: The script will run on a Sun Cobalt Linux 2.2 box (i believe its
>a sun tailored distro...)

>thanks for your help on this matter, Nick


>> I've developed the following script which is meant to retrieve xml
>> data from a webpage, but i need any '&' to be changed to '&amp;'. I'm
>> running this through an awk command but the output either never gets
>> written to the file (i.e. the file is created and is blank) or the
>> file never gets created.

>> any help would be greatly appreciated (for starters, is the awk
>> command correct??)

>> Thanks, Nick

>> ************************************************************************

>> #!/bin/sh

>> # Get IT reseller XML news feed
>> (lynx -source http://www.cw360asp.com/News_Feeds/Extraction.asp?feed=Reseller_Break...)
>> > resellernews.tmp

>> # Change all of the & characters to read as &amp;, this will stop the
>> XML parsing routines from falling over
>> awk '{ gsub(/&/, "&amp;"); print $0 > "resellernews.xml"}'
>> resellernews.tmp

>> # destroy .tmp and .new files (we only need the .xml and .old files)
>> rm resellernews.tmp

--
Floyd L. Davidson         <http://www.ptialaska.net/~floyd>

 
 
 

Bash Shell Script Problems - Advice Needed

Post by Nick Hepplest » Thu, 08 Nov 2001 20:13:14


Ok, i current have:

#!/bin/sh
news_path=/home/sites/home/users/admin/web/news

# Get IT reseller XML news feed
(lynx -source http://www.cw360asp.com/News_Feeds/Extraction.asp?feed=Reseller_B\
reaking_and_Daily_News_xml&site=Midwich) > ${news_path}/resellernews.tmp

# Get User XML news feed
(lynx -source http://www.cw360asp.com/News_Feeds/Extraction.asp?feed=User_Break\
ing_and_Daily_News_xml&site=Midwich) > ${news_path}/breakingnews.tmp

sed -e 's/&/&amp;/g' < ${news_path}/resellernews.tmp > ${news_path}/resellernew\
s.xml
sed -e 's/&/&amp;/g' < ${news_path}/breakingnews.tmp > ${news_path}/breakingnew\
s.xml

rm ${news_path}/*.tmp

any help, greatly appreciate, cheers,

Nick



> >Thanks for your help guys. I've tried the sed command and it works
> >fine - from the command prompt... When i place it into a script the
> >'new' file is created, but with no data.

> Without seeing exect (cut and paste, not retyped) copies of the your
> scripts it is somewhat difficult to determine what you have.

> >To get my head around where the problem is, i now have 2 scripts, one
> >retrieves the xml data (via lynx) and simply dumps the output to file.
> >a second script then  runs the sed/awk command. when i run these
> >scripts independently of each other, i.e. from the command prompt with
> >a pause of ~10 seconds, i have no problems, when i call the second
> >script form the first (in a feeble attempt at automation...) the .xml
> >files have 0 bytes of data...

> >Is there a 'sleep' method that i can call to halt the processing for
> >2-3 seconds before running the sed/awk command??

> >Note: The script will run on a Sun Cobalt Linux 2.2 box (i believe its
> >a sun tailored distro...)

> >thanks for your help on this matter, Nick


> >> I've developed the following script which is meant to retrieve xml
> >> data from a webpage, but i need any '&' to be changed to '&amp;'. I'm
> >> running this through an awk command but the output either never gets
> >> written to the file (i.e. the file is created and is blank) or the
> >> file never gets created.

> >> any help would be greatly appreciated (for starters, is the awk
> >> command correct??)

> >> Thanks, Nick

> >> ************************************************************************

> >> #!/bin/sh

> >> # Get IT reseller XML news feed
> >> (lynx -source http://www.cw360asp.com/News_Feeds/Extraction.asp?feed=Reseller_Break...)
> >> > resellernews.tmp

> >> # Change all of the & characters to read as &amp;, this will stop the
> >> XML parsing routines from falling over
> >> awk '{ gsub(/&/, "&amp;"); print $0 > "resellernews.xml"}'
> >> resellernews.tmp

> >> # destroy .tmp and .new files (we only need the .xml and .old files)
> >> rm resellernews.tmp

 
 
 

1. Convert Bash shell script to Korn shell script

The following bash script works fine to delete all files that are
older than $1 minutes. To execute this script,
bash cleanup +10

find /mypath -type f -cmin $1 -exec rm -f {} \;

Unfortunately, now I just realize I need to make it work in Korn
Shell. Even I
change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the
script by ksh cleanup +10, it still have
different errors:

cleanup[9]: -cmin:  not found.
cleanup[10]: -type:  not found.

Looks like it doesn't work anymore. I think I need to re-write the
Korn Shell script that do the task.
I tried to search for equivalent Korn shell commands but unsuccessful.

Please help. thanks!!

2. SSL

3. BASH BASH BASH BASH BASH BASH BASH BASH BASH BASH

4. Buffalo Wirless - docs

5. Need advice for modifying passwd file in shell script

6. WAIS

7. Bash: Getting rubbish parameters when script first run in a new bash shell

8. Discuss: your filesystem backup strategy

9. Copy files using filenames from text files with shell script or bash script

10. Seeking advice on shell scripting problem.

11. bash shell script problem

12. Problem with BASH shell scripts...???

13. Can a ksh shell script be executed without problems under bash?