Operating System - HP-UX
1831628 Members
3056 Online
110027 Solutions
New Discussion

"cannot open input file" with a script using the split command

 
SOLVED
Go to solution
MAD_2
Super Advisor

"cannot open input file" with a script using the split command

I have createad a script using the following syntax:

split -b nm /dir/inputfile /dir/outputfile
or
split -b nk /dir/inputfile /dir/outputfile
or
split -l n /dir/inputfile /dir/outputfile

as specified by the user. The script is attached.

Problem: If I do everything manually it works fine, but while running the script I am getting the "cannot open input file"... What am I overlooking?

Thanks!
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
6 REPLIES 6
James Murtagh
Honored Contributor

Re: "cannot open input file" with a script using the split command

reboot
James Murtagh
Honored Contributor

Re: "cannot open input file" with a script using the split command

Hi there,

My upmost apologies. I leave my computer on so my flatmates can browse the internet....it seems now they cannot be trusted. I hope this hasn't discouraged your use of the forum.

If you set a shell echo in your script, i.e. run :

# ksh -x <script>

You will have a better idea where the script is failing.

Again, I am very sorry.

Regards,

James.

Steven E. Protter
Exalted Contributor

Re: "cannot open input file" with a script using the split command

Jame's idea is excellent.

You might want to add tests for the existance of the file involved into your script.

if [ -f filename $filename ] stuff.

My crib sheet isn't handy right now.

reboot huh?

Sure, it was the roommates.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Michael Schulte zur Sur
Honored Contributor
Solution

Re: "cannot open input file" with a script using the split command

Hi,

you have a small error in your script.
split -b $KBSIZEk $WKDIR/$FILENAME $RESDIR/$FILENAME.
The shell evaluates the variable $KBSIZEk because it can not know, that k is not part of the variable name and of course this will
result in nothing, because it is not set.
use ${KBSIZE}k
Now the skell knows, what to evaluate.
Also the 1st line should be
#!/usr/bin/ksh

greetings,

Michael
Jeroen Peereboom
Honored Contributor

Re: "cannot open input file" with a script using the split command

L.S

Michael is completely right about the variables. Iy may be a small error, but small errors tend to be fatal for your scripts.
Your first line is wrong too, as Michael says.

You may want to add a line near the beginning:
set -u # undefined variable -> error

If the shell encounters an undefined variable, it will complain about that.

For debugging, add a 'set -xv'.

Good luck.

JP
MAD_2
Super Advisor

Re: "cannot open input file" with a script using the split command

Michael's response is what fixed my problem, the brackets around the variable names (like the example he used of ${KBSIZE}k instead of simply $KBSIZEk) was probably what was causing the problem, those variables and the first line of my script were the only things I changed before I tried again and then everything worked as expected.

Once again, you guys are great... Thanks!
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with