- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Scripting issue.
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
Discussions
Discussions
Forums
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
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
тАО07-12-2006 04:16 AM
тАО07-12-2006 04:16 AM
the format of the file name is fairly simplistic.
the customer puts file in a staging area, I have a destination folder
What I've done is defined some variables and am trying to parse into the file name to see the DOCID in the destination folder exists compared to the staged files, and if it exists then I want to increment the DOCID by one during the cp.
my script thus far is fairly simplistic, I have to get it running in cron so I don't have to baby sit a user process..
I have a CASE statement that looks at the file name and pulls the DISTID so I can apply the correct destination folder.
#!/bin/bash
export p1=/upload_resumes/rextest/
export p2=/upload_resumes/backup/
export p3=/mps-docs/mps-docs/app-staging/rextest/
for fn in `ls /mps-docs/mps-docs/app-staging/`
do
for dist in `echo $fn |awk '{print substr($1,1,3)}'`
# DISTRICT SPECIFIC INFORMATION
do
export dist
case $dist in
wst)
export distpath="$wst"
;;
mps)
export distpath="$mps"
;;
esu)
export distpath="$esu"
;;
plv)
export distpath="$plv"
;;
ral)
export distpath="$ral"
;;
*)
;;
esac
Then i need to look at the file name again to pull our the DOCID and check the DOCID against the destination folder. The customer has thus far given the APPID of NEW or ADD, which makes the cp a bit more problematic.
the file name generally will look like this.
mpsplus_1234_1.pdf or mpsplus_1234_2.pdf the _2.pdf can be as many as _99.pdf
I am drawing a blank on my scripting brain for some reason today.
Any scripting guys with some ideas I'd appreciate it.
Rex Mueller
Solved! Go to Solution.
- Tags:
- bash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 04:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 04:49 AM
тАО07-12-2006 04:49 AM
Re: Scripting issue.
for fn in /mps-docs/mps/docs/app-staging/*
do
__echo $fn | cut -d. -f1 |
____IFS=_ read distID appID docID
__echo $fn | cut -d. -f2 | read ext
__eval distpath="$dist"
__if [[ -z $distpath ]]; then
____print "ERROR: invalid distID $distID"
____exit 1
__fi
__while [[ -f ${distpath}/${distID}_${appID}_${docID}.${ext} ]]
__do
____(( docID += 1 ))
____if (( docID > 99 )); then
______print "ERROR: docID too high!"
______exit 2
____fi
__done
__mv $fn ${distpath}/${distID}_${appID}_${docID}.${ext}
done
---
you may want to add some echo statements to see that your variables are set correctly, and you may want to do "typeset -Z2 docID" to make sure you always have a 2 digit docID (it adds the leading zero for #<10).
the eval statement saves you from your big case statement, and the following if validates that the env var for the distID was set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 04:52 AM
тАО07-12-2006 04:52 AM
Re: Scripting issue.
eval distpath="\${$dist}"
the leading "_" on each line are to simulate spaces, so you the forum doesn't mess up the indentation of the script
- Tags:
- eval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 05:06 AM
тАО07-12-2006 05:06 AM
Re: Scripting issue.
You can (recently) chekc the "Retain Format" box at the bottom of your post to cause leading spaces to be retained for formatting scripts.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 05:11 AM
тАО07-12-2006 05:11 AM
Re: Scripting issue.
greg's idea looks like it will probably do the trick but I was having a major brain drain this morning.
Cold Wendy's fries don't help matters either. :(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 05:13 AM
тАО07-12-2006 05:13 AM
Re: Scripting issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2006 01:36 AM
тАО07-13-2006 01:36 AM
Re: Scripting issue.
here is what I am trying,
I am defining some of the more static variables first such as
export SOURCEDIR="/mps-docs/mps-docs/app-staging/"
export DESTDIR="/web-folder/"
This script is driven by one of my school districts, hence the district ID..
I define the distid in a case statement. the dbname is
the basic concern is
moving files from a static directory to another static directory, but looking at the APPID and DOCID.
IF THE APPID ID exists in the DESTINATION FOLDER, with a specific DOCID then increment the DOCID + 1 and retain the extension.
It looks as though if I define the FILENAME first, then parse for the sub variables within the document name and increment the DOCID with portions from you guys I can probably get it to work.
I will muck with it today, and see if I can get it running. Thanks again.
- Tags:
- IFS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2006 02:27 AM
тАО07-13-2006 02:27 AM
Re: Scripting issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-13-2006 06:29 AM
тАО07-13-2006 06:29 AM
Re: Scripting issue.
#!/bin/bash
export distpath=/upload_resumes/rextest/
export source=/mps-docs/mps-docs/app-staging/rextest/
cd $source
for fn in `ls`
do
echo $fn
echo $distpath
export distID=`echo $fn |awk -F_ '{print $1}'`
export appID=`echo $fn |awk -F_ '{print $2}'`
export docID=`echo $fn |awk -F_ '{print $3}'|cut -d. -f1`
export ext=`echo $fn |awk -F_ '{print $3}'|cut -d. -f2`
echo $fn |cut -d. -f2 | read ext
echo $distID
echo $appID
echo $docID
echo $ext
read
if [[ -z $distpath ]]; then
echo "ERROR: invalid distID $distID"
exit 1
fi
while [[ -f ${distpath}/${distID}_${appID}_${docID}.${ext} ]]
do
(( docID += 1 ))
if (( docID > 99 )); then
echo "ERROR: docID too high!"
exit 2
fi
done
cp $fn ${distpath}mpsplus_${appID}_${docID}.${ext}
done