- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh help please
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
07-11-2003 10:17 AM
07-11-2003 10:17 AM
I know most of you can do this in your sleep, not me.
What I need should be fairly simple. I want to move selected files from one drive/jobdir to another drive/jobdir. The job # is always the same on both drives ex. 29999 but of course the job number changes with each job.
So in the following script, I enter $cadf 29999
at the prompt and want to select from a list of files to move from /appe/anydir/29999 to /appc/anydir/29999, (anydir would be subdirs between drive name and job number).
Here's what I have that works so far. I have trouble getting scripts to be interactive asking questions.
#!/bin/ksh
# @(#)cadf
# located /sjs/cadf
#
# program searches /appe dirs for job number dir, gets a list of files in dir,
# asks which files you want, then moves the files to /appc dir for same job
# number
#
set -x # for debugging
E=$(find /appe/eng -name $1)
cd $E
engdir=$(pwd)
C=$(find /appc/cad -name $1)
for f in $engdir
do
mv -i $engdir/* $C/
done
Thanks for any help.
John
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2003 10:40 AM
07-11-2003 10:40 AM
Solution1) is there only one /appe/anydir/29999
or is it possible that /appe/anydira/29999 and /appe/anydirb/29999 both exist.
2) same as 1 except for /appc/anydir
3) is there a one to one correspondence between /appe/anydir/29999 and /appc/anydir/29999, ie /appe/a/b/29999 always matches /appc/a/b/29999
4) will both directories always exist
5) do you want to overwrite any files in /appe/anydir/29999 regardless if they exist or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2003 10:57 AM
07-11-2003 10:57 AM
Re: ksh help please
1-2) /appe and /appc are always constant drive names.
the job number only exists once on each drive.
3) not always. anydir can sometimes be variable.
4) yes.
5) yes. I would want to overwrite files going from /appe/... to /appc/...
It would be nice to have it ask and/or give the option to change the name.
Thanks,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2003 11:06 AM
07-11-2003 11:06 AM
Re: ksh help please
fromDir=/appe/eng
toDir=/apc/cad
file=$1
PS3='please enter a number -> '
select i in $(find $fromDir -name $file)
do
case $i
${fromDir}*${file})
tmpDir=${i#$fromDir/}
tmpDir="$toDir/$tmpDir"
break;;
*) print "invalid number";;
esac
mv $fromDir/* $tmpDir;;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2003 11:19 AM
07-11-2003 11:19 AM
Re: ksh help please
ran it using cadf 29999
get /sjs/cadf[58]: syntax error at line 62 : `${fromDir}*${file}' unexpected
John
Getting near quitting time. They make me leave at 3:30 on Friday. I'll be able to work on it more on Monday.
Have a Great Weekend.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2003 11:22 AM
07-11-2003 11:22 AM
Re: ksh help please
the 29999 is a directory. the files under it are what we need, the file names are unknown.
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2003 11:24 AM
07-11-2003 11:24 AM
Re: ksh help please
do you want to only ask for a new file name if the file already exists
of ask for each file
your start is pretty good
E=$(find /appe/eng -name $1)
cd $E
engdir=$(pwd)
C=$(find /appc/cad -name $1)
for f in $(ls $engdir )
do
if [ -f ${engdir}/$f ] ;then #only do files
if [ -f $C/$f ] ;then
# do this if the file already exists
print "$C/f already exists do you want to overwrite it (y/n)? "
read answer
case $answer in
#if yes just overwrite the file
[Y|y]*) mv $engdir/$f $C/$f;;
#anything else ask for a new file name
*) print "what do you want to rename the file, $f, as? "
read answer
#might want to do some testing for valid per naming standard
mv $engdir/$f $C/$answer ;;
esac
else #file doesn't exist so just copy it
mv $engdir/$f $C/$f
fi
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2003 11:31 AM
07-11-2003 11:31 AM
Re: ksh help please
select i in $(find $fromDir -name $file)
do
case $i
${fromDir}*${file})
tmpDir=${i#$fromDir/}
tmpDir="$toDir/$tmpDir"
break;;
should be
case $i in #need that "in"
${fromDir}*${file})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2003 11:33 AM
07-11-2003 11:33 AM
Re: ksh help please
quick response, they are kicking me out.
"do you want to only ask for a new file name if the file already exists" yes
would like a list to choose which files to copy first. with numbers for each filename perhaps, then choose 1,3 4-7 or quit choices.
Then it would see if the file exists on /appc and allow for overwrite or rename choice?
John
Talk to you Monday.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2003 11:41 AM
07-11-2003 11:41 AM
Re: ksh help please
*) notDone=/usr/bin/false
while $notDone
do
print "what do you want to rename the file, $f, as? "
read answer
#might want to do some testing for valid per naming standard
if [ "$answer = "" ] ;then #user just typed enter
print "you'll have to enter a file name"
else
if [ -f $C/$f ] ;then
print "$f already exists, you'll need to select a different name"
else
mv $engdir/$f $C/$answer
notDone=/usr/bin/false
fi
fi
done;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2003 11:42 PM
07-13-2003 11:42 PM
Re: ksh help please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 03:55 AM
07-14-2003 03:55 AM
Re: ksh help please
I take it that parts of my script should be modified and left at the beginning?
I ran your script and it listed all dirs/files in /appe/eng then gives me the folowing syntax error:
+ PS3=please enter a number ->
/sjs/cadf[19]: syntax error at line 23 : `${fromDir}*${file}' unexpected
I tried adding my 2 find variables and got it to list the dir but still get the same syntax error.
You're way over my head here. That's what makes this forum such an asset. I do O.K. with small scripts doing 1-2 things, but having a single script do it all is where I'm weak. I usally just end up writing several scritps that are run from a main script. Not really the way I want it, but it works most of the time.
In my next post I'll attach an example script that I wrote so you can see an example of what I mean.
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 03:59 AM
07-14-2003 03:59 AM
Re: ksh help please
attached single/multi script example mentioned above.
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 04:05 AM
07-14-2003 04:05 AM
Re: ksh help please
BTW, points are the easy part, you earned them! You are doing the hard part.
This is the best forum on the net. All of you are a big help.
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:16 AM
07-14-2003 06:16 AM
Re: ksh help please
No, the script I attached should be all you need. The #!/usr/bin/ksh should start at column 1. And, feel free to add as many comments as you need. After all, your the one that needs to know how things are done.
I ran your script and it listed all dirs/files in /appe/eng then gives me the folowing syntax error:
+ PS3=please enter a number ->
/sjs/cadf[19]: syntax error at line 23 : `${fromDir}*${file}' unexpected
this is for the same reason I had mention previously, the "case" statement just after the PS3 assignment is missing it's "in".
select i in $(find $fromDir -name $file)
do
case $i
${fromDir}*${file})
should be
select i in $(find $fromDir -name $file)
do
case $i in ${fromDir}*${file})
But, with the script a provided none of that is necessary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:20 AM
07-14-2003 06:20 AM
Re: ksh help please
ask as many questions as you'd like. I'll, or others, will try to answer them as best we can.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 07:13 AM
07-14-2003 07:13 AM
Re: ksh help please
That works. I'll test it for different scenario's. Also in an attempt to learn from this experience, I'll try to make it do other things. ex. for the question, allow multiple choices 1-3,6,8-10 or all files.
If I get stuck again, do I post it here, or post a new question? It may be toward the middle to latter part of this week before I get it done. They make me work here too? can you believe it?
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 07:16 AM
07-14-2003 07:16 AM
Re: ksh help please
Let me be the first to congratulate you on your ne hat.
Congratulations and great job!!!
Keep up the good work.
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 07:20 AM
07-14-2003 07:20 AM
Re: ksh help please
that would be "new hat" not "ne hat"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 07:39 AM
07-14-2003 07:39 AM
Re: ksh help please
once the question poser has assigned a value of 8-10 for one of his answers the thread gets a bunny icon attached to it. Usually this means that the author has received a very good answer to his question.
And being the author already has an answer most forum members will discontinue following that thread.
So, I'd post a new question. That way more forum members will be likely to answer your question. I'd also put a url to this thread in the new post. That way someone can always go back to this thread as reference if they desire.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 08:14 AM
07-14-2003 08:14 AM
Re: ksh help please
all files is pretty easy. attached is the script with an all files option. you can do a diff and see what changes i've made. Maybe that will help you with making further changes.
Congratulations on the new hat and great job!!!
Thanks
It is always nice to help those that appreciate my work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 09:31 AM
07-14-2003 09:31 AM
Re: ksh help please
Thanks for all the help.
The script works great! It'll also give me alot of things that I can apply to existing scripts.
I consider this question closed.
John