- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting question - mkdir statement
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
тАО01-13-2009 07:59 AM
тАО01-13-2009 07:59 AM
if the "TRANSCRIPT Folder" exist the script will move a file per directive, I have an IF statement that says if the Folder for this APPID does not exist mkdir the Transcripts directory before copying the file.
I would like to ask for other eyes to see what problems exist in this script that maybe be disallowing this script to work. The top of the script is mostly defining variable the bottom is what seems to be causing my difficulty.. Any insight or thought appreciated.. This is a homegrown document management system for one of our districts HR departments.
#!/bin/bash
export destpath=/mps-docs/mps-docs/applicant/
export source=/mps-docs/mps-docs/transcript-staging/
export backuppath=/mps-docs/mps-docs/transcript-backup/
mv /tmp/mps_temp.log /tmp/mps_temp.log.`date +%Y%m%d`
touch /tmp/mps_temp.log
echo > /tmp/mps_temp.log
echo `mount |grep mps-docs ` >> /tmp/mps_temp.log
cd $source
for fn in `ls`
do
ls $source >> /tmp/mps_temp.log
echo Source Location $source >> tmp/mps_temp.log
echo Filename in Source Location $fn >> /tmp/mps_temp.log
echo Destination Path $destpath >> /tmp/mps_temp.log
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 tID=`echo $fn |awk -F_ '{print $4}'|cut -d. -f1`
export ext=`echo $fn |awk -F_ '{print $4}'|cut -d. -f2`
echo $fn |cut -d. -f2 | read ext
echo $fn >> /tmp/mps_temp.log
echo $destpath$appID >> /tmp/mps_temp.log
ls $destpath$appID >> /tmp/mps_temp.log
echo $destpath$appID/Transcripts >> /tmp/mps_temp.log
ls $destpath$appID/Transcripts/ >> /tmp/mps_temp.log
if [[ -z $destpath ]]; then
echo "ERROR: invalid distID $distID"
exit 1
fi
while [[ -f ${destpath}/${appID}/Transcripts/${distID}_${appID}_${docID}_${tID}.${ext} ]]
do
(( docID += 1 ))
if (( docID > 99 )); then
echo "ERROR: docID too high!"
exit 2
fi
done
#####################################################################
#### ADDED DOUBLE QUOTE AROUND TEST VALUE - 12-28-2008 RCM ESU#3 ####
#####################################################################
if [ -d "${destpath}/${appID}/Transcripts" ]
then
cp -f $fn ${destpath}/${appID}/Transcripts/${distID}_${appID}_${docID}_${tID}.${ext}
echo Transcript Folder Exists and Files copies shown >> /tmp/mps_temp.log
ls ${destpath}/${appID}/Transcripts >> /tmp/mps_temp.log
mv ${source}${fn} ${backuppath}/
echo Backup of original files moved from ${source}${fn} to ${backuppath}/ >>/tmp/mps_temp.log
else
mkdir ${destpath}/${appID}/Transcripts
cp -f $fn ${destpath}/${appID}/Transcripts/${distID}_${appID}_${docID}_${tID}.${ext}
echo Transcript Folder Create and Files copies shown >> /tmp/mps_temp.log
ls ${destpath}/${appID}/Transcripts >> /tmp/mps_temp.log
mv ${source}${fn} ${backuppath}/
echo Backup of original files moved from ${source}${fn} to ${backuppath} >>/tmp/mps_temp.log
fi
done
Solved! Go to Solution.
- Tags:
- mkdir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 08:11 AM
тАО01-13-2009 08:11 AM
SolutionOne way to avoid surprises and quickly find problems is to have your scrip fail when a variable isn't set.
#!/usr/bin/sh
set -u
...
Another thing I like to do when doing 'mkdir's is to issue them as:
# mkdir -p
...such that all intermediate paths are created in one simple statement.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 08:15 AM
тАО01-13-2009 08:15 AM
Re: Scripting question - mkdir statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 08:17 AM
тАО01-13-2009 08:17 AM
Re: Scripting question - mkdir statement
I would also add that you can use perform an automatic 'chmod' to set the permissions of the directory when you make it, since I don't see an explicit 'umask' declaration in your script and thus you are at the mercy of what you inherit:
# mkdir -p -m 775 ${mydir}/{mysubdir1}/${mysubdir2}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 08:20 AM
тАО01-13-2009 08:20 AM
Re: Scripting question - mkdir statement
mkdir -p -m 775 ${destpath}/${appID}/Transcripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 08:28 AM
тАО01-13-2009 08:28 AM
Re: Scripting question - mkdir statement
> so make it look as such:
mkdir -p -m 775 ${destpath}/${appID}/Transcripts
Yes, that's the idea, although you may want an absolute path:
# mkdir -p -m 775 /${destpath}/${appID}/Transcripts
The permissions are entirely your choice, too.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 08:31 AM
тАО01-13-2009 08:31 AM
Re: Scripting question - mkdir statement
I will fix these as well Thanks for the assist.. I will monitor the outcome and close this thread accordingly..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2009 11:23 PM
тАО01-14-2009 11:23 PM
Re: Scripting question - mkdir statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-15-2009 06:23 AM
тАО01-15-2009 06:23 AM