- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help with a script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 07:17 AM
05-29-2008 07:17 AM
Here is what I am trying to run.
PATH=/sbin:/usr/sbin:/usr/bin:/opt/pgp-6.5.8;export PATH
WAND=/home/wand;export WAND
WANDSAVE=/home/wand/SAVE;export WANDSAVE
DATE=$(date '+%Y%m%d');export DATE
TIME=$(date '+%H%M%S');export TIME
echo $DATE
echo $TIME
export FTPSERVER=xxx.x.x.xxx
cd $WAND
mv people_error_*.txt.pgp /tmp/
mv people_error_*.txt /tmp/
/usr/bin/cp -p testfile* $WANDSAVE/
ls testfile* >/tmp/testfile.out
for file in '/tmp/testfile.out'
do
sleep 30
/usr/bin/mv $file people_error_"$DATE"_"$TIME".txt
/opt/pgp-6.5.8/pgp -e people_error_*.txt PGP-Key
/usr/bin/echo "`/usr/bin/date` Starting FTP process"
/usr/bin/echo "user xxxxxxx xxxxxxxx\nbin\nput people_error_*.txt.pgp\nbye" >/
p/ftpin_error.tmp
/usr/bin/ftp -n -i $FTPSERVER
/usr/bin/echo "`/usr/bin/date` ending FTP process"
rm /tmp/ftpin_error.tmp
done
Any help would be appreciated and points awarded.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 07:44 AM
05-29-2008 07:44 AM
Re: Help with a script
that this was doing?:
for file in '/tmp/testfile.out'
do
It's not _reading_ "/tmp/testfile.out".
td192> cat f1.sh
#!/bin/sh
for file in '/tmp/testfile.out'; do
echo $file
done
td192> ./f1.sh
/tmp/testfile.out
It is possible to read names from a file, but
this is not one of the ways.
For diagnostic/educational purposes, you may
find it helpful to run your script with "-v"
and/or "-x" options ("sh -x f1.sh").
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 07:47 AM
05-29-2008 07:47 AM
Re: Help with a script
I think your 'for' loop needs an adjustment. If you put an echo $file statement under your 'for/do' loop, you'll see that only /tmp/testfile.out gets returned and the loop exits.
Try:
for file in `cat /tmp/testfile.out`
do
done
Regards,
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 08:16 AM
05-29-2008 08:16 AM
Re: Help with a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 08:25 AM
05-29-2008 08:25 AM
Re: Help with a script
If you want to read a file do something like this:
#!/usr/bin/sh
while read LINE
do
echo ${LINE}
done < /etc/hosts
...This can be ammended to read and split a line into its components. For example, if you only want the first "word" (based on the current setting of 'IFS'):
while read FIRST REST
do
echo ${FIRST}
done < /etc/hosts
...or, change the 'IFS' (inter-field-seperator) to a colon:
OLDIFS=${IFS}
IFS=":"
while read FIRST REST
do
echo ${FIRST}
done < /etc/passwd
IFS=${OLDIFS}
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 08:43 AM
05-29-2008 08:43 AM
Re: Help with a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 08:54 AM
05-29-2008 08:54 AM
Re: Help with a script
To move a file:
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
while read FILE
do
mv ${FILE} ${FILE).${TIMESTAMP}
done < inputlist
...It is good technique to use the curly braces to surround your variables. This avoids ambuguity.
As for your FTP portion, you could reference your local and remote filenames as variables ( ${localfile} and ${remotefile} ). Then, you can pass what you need.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 10:10 AM
05-29-2008 10:10 AM
Re: Help with a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 10:36 AM
05-29-2008 10:36 AM
Re: Help with a script
One problem with the ${TIMESTAMP} variable I built for you is that it is static.
You can do (better) with:
# mv ${FILE} ${FILE}.$(date +%Y%m%d_%H%M%S)
...as written. This causes the evaulation "on-the-fly" and if a second passes between moves, the file's name reflects that.
Of course, in a loop, you can also impose a wait with:
# sleep 1
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 10:39 AM
05-29-2008 10:39 AM
Re: Help with a script
> only get /tmp/testfile.out. Not sure
> why....
Probably because you didn't do exactly what
was suggested, and there's a difference
between "'" and "`".
td192> cat f3.dat
aaa
bbb
td192> cat f3.sh
#!/bin/sh
for file in ` cat f3.dat `; do
echo $file
done
td192> ./f3.sh
aaa
bbb
As usual, a precise and accurate description
of what you did, and what happened when you
did it, might be helpful.
> [...] my only problem now [...]
Oh, I doubt that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 10:51 AM
05-29-2008 10:51 AM
Re: Help with a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 10:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2008 12:05 PM
05-29-2008 12:05 PM
Re: Help with a script
thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2008 02:36 AM
05-30-2008 02:36 AM
Re: Help with a script
(You shouldn't be using cat, that's evil. :-)
There are two basic ways to handle files with files. Either use while, as JRF said:
while file; do
...
done < file
Or if a "limited" number that will fit in a shell command line, you can use for (an improvement of Steven's case):
for file in $(< file); do
...
done
Note: No cats needed.
As a coding style, unless your other shell scripts need these variables, you shouldn't export them:
DATE=$(date '+%Y%m%d');export DATE
TIME=$(date '+%H%M%S');export TIME
And if you using a real shell, you can use the export command directly:
export FOO=bar
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2008 03:56 AM
05-30-2008 03:56 AM
Re: Help with a script
As Dennis noted, 'cat's can be evil.
Well-behaved (written) Unix filters will read files passed as commandline arguments, or take their input from STDIN as from a pipe's output.
Thus, when someone writes (variously):
# cat file | awk ...
# cat file | grep ...
...they are creating a needless extra process and wasting I/O. The 'cat' process reads a file and writes each line of output which is then *read* again by another process only to filter and *write* something. Instead, one should write:
# awk '{ ... }' file
# grep whatever file
Regards!
...JRF... [ who happens to like cats (as animals) ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2008 05:03 AM
05-30-2008 05:03 AM
Re: Help with a script
Hey. Don't blame me for that "cat". I was
only offering an illustration of how the
previous suggestion actually _does_ work
(with the right punctuation). As I said, "It
is possible to read names from a file, but
this is not one of the ways." The one of
those ways which I'd prefer is a while-read
like that suggested by Mr. Ferguson, which
allows more flexible processing more easily.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2008 07:29 AM
05-30-2008 07:29 AM
Re: Help with a script
I like to use "set -x" at the begining of scripts and in functions while testing. It helps to debug... Just thought it might help.
Tommy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2008 07:34 AM
05-30-2008 07:34 AM