Cee Vee
asked on
tcsh shell script cannot open newly created file
in a tcsh script, I created a new file in a different directory. in the same script in the later part, I tried to open the file I just created, it returned "cannot open...."
I've checked everything and positive that the path is correct. Now if I exit the script and run the same command, then the file opens OK
My suspect is that because the file is newly created so there maybe some delay and the script cannot recognize it.
Can you help ?
I've checked everything and positive that the path is correct. Now if I exit the script and run the same command, then the file opens OK
My suspect is that because the file is newly created so there maybe some delay and the script cannot recognize it.
Can you help ?
Did you close the file that you created?
Some code would be extremely useful.
ASKER
Here is part of the script
echo "osfetch_linux $default_ip $filename"
# Fetch data from Musti box
osfetch_linux $default_ip $filename
# Split it up
set split_dir = $filename'_'$chunk_size
mkdir $split_dir
split -b $chunk_size $filename $split_dir/$filename
# List available splitted chunks for user to select
set ii = 1
set splitted_chunks = `ls $split_dir`
foreach item ( `ls $split_dir` )
if( ! -d "$1/$item" ) then
set splitted_chunks[$ii] = $item
echo $ii - $item
@ ii++
endif
end
# User selection
echo -n "Enter chunk # to translate: "
set inputline = $<
set chunk_to_translate = $splitted_chunks[$inputlin e]
set chunk_to_translate = $split_dir/$chunk_to_trans late
echo "chunk_to_translate == <$chunk_to_translate>"
# Translate it
ibuprofen_linux $chunk_to_translate
echo "osfetch_linux $default_ip $filename"
# Fetch data from Musti box
osfetch_linux $default_ip $filename
# Split it up
set split_dir = $filename'_'$chunk_size
mkdir $split_dir
split -b $chunk_size $filename $split_dir/$filename
# List available splitted chunks for user to select
set ii = 1
set splitted_chunks = `ls $split_dir`
foreach item ( `ls $split_dir` )
if( ! -d "$1/$item" ) then
set splitted_chunks[$ii] = $item
echo $ii - $item
@ ii++
endif
end
# User selection
echo -n "Enter chunk # to translate: "
set inputline = $<
set chunk_to_translate = $splitted_chunks[$inputlin
set chunk_to_translate = $split_dir/$chunk_to_trans
echo "chunk_to_translate == <$chunk_to_translate>"
# Translate it
ibuprofen_linux $chunk_to_translate
ASKER
I tried to wait for sometimes before making the selection, but still same result "File not found or file cannot be opened." .... as soon as I exit the script, and run it again (hard code exact filename printed out to terminal just to test), then the file opens ok.
Does this line cause error?
ibuprofen_linux $chunk_to_translate
if so, add
echo "----------"
echo $ii
echo $split_dir
echo $chunk_to_translate
ls -l $split_dir
ls -l $chunk_to_translate
echo "----------"
before it. What do you get?
ibuprofen_linux $chunk_to_translate
if so, add
echo "----------"
echo $ii
echo $split_dir
echo $chunk_to_translate
ls -l $split_dir
ls -l $chunk_to_translate
echo "----------"
before it. What do you get?
does ibuprofen_linux try to open any other files besides $chunk_to_translate?
ASKER
--> amit_q : this is what came out
Max received packet size was 18824.
Data bytes received 5997416
Speed 5856.85 KB/s
1 - t6aa
2 - t6ab
3 - t6ac
4 -
Enter chunk # to translate: 2
chunk_to_translate == <t6_2000k/t6ab>
----------
5
t6_2000k
t6_2000k/t6ab
total 5384
-rw-rw-r-- 1 kevo sw1 2048000 Mar 21 17:46 t6aa
-rw-rw-r-- 1 kevo sw1 2048000 Mar 21 17:46 t6ab
-rw-rw-r-- 1 kevo sw1 1901416 Mar 21 17:46 t6ac
ls: t6_2000k/t6ab: No such file or directory
Exit 1
----------
File not found or file cannot be opened.
Exit 255
Max received packet size was 18824.
Data bytes received 5997416
Speed 5856.85 KB/s
1 - t6aa
2 - t6ab
3 - t6ac
4 -
Enter chunk # to translate: 2
chunk_to_translate == <t6_2000k/t6ab>
----------
5
t6_2000k
t6_2000k/t6ab
total 5384
-rw-rw-r-- 1 kevo sw1 2048000 Mar 21 17:46 t6aa
-rw-rw-r-- 1 kevo sw1 2048000 Mar 21 17:46 t6ab
-rw-rw-r-- 1 kevo sw1 1901416 Mar 21 17:46 t6ac
ls: t6_2000k/t6ab: No such file or directory
Exit 1
----------
File not found or file cannot be opened.
Exit 255
ASKER
--> ozo : no it doesn't open any other file
FYI : If i don't create the new directory, and not spliting the file....it works fine
FYI : If i don't create the new directory, and not spliting the file....it works fine
How long does split command take? Is script blocked when the split is happening? You can check by adding date command before and after split command
date
split -b $chunk_size $filename $split_dir/$filename
date
date
split -b $chunk_size $filename $split_dir/$filename
date
and inanimately after the script throws error what do you get if you do
ls -l t6_2000k/t6ab
Use the same filename that threw the error as soon as possible.
ls -l t6_2000k/t6ab
Use the same filename that threw the error as soon as possible.
ASKER
--> amit_q : putting date around split command resulted
Speed 6613.22 KB/s
Wed Mar 21 17:59:31 PDT 2007
Wed Mar 21 17:59:32 PDT 2007
1 - t8aa
Speed 6613.22 KB/s
Wed Mar 21 17:59:31 PDT 2007
Wed Mar 21 17:59:32 PDT 2007
1 - t8aa
Try to put a larger sleep (say a min or so). A 5Gb file getting splitted in 1 seconds with 2 new files of 2 GB and 1 new file of 1 GB doesn't seem right. It has to take more than 1 seconds. What o/s you have?
Also as soon as you get the error, do ls -l of the same file that caused error. You probably would get the same error if you execute the ls -l soon enough after the completion (failure) of the script.
Also as soon as you get the error, do ls -l of the same file that caused error. You probably would get the same error if you execute the ls -l soon enough after the completion (failure) of the script.
Nevermind, it is 5MB not GB as I misunderstood.
try
echo "chunk_to_translate == <$chunk_to_translate>" | od -c
echo "chunk_to_translate == <$chunk_to_translate>" | od -c
ASKER
--> amit_q : it's 5MB not 5GB, and you're right, ls also returns fail
chunk_to_translate == <t1_2000k/t1ab>
File not found or file cannot be opened.
Exit 255
ls: t6_2000k/t6ab: No such file or directory
Exit 1
is there anything wrong with my string $chunk_to_translate ? maybe any hidden chracter even though i didn't see it in echo
chunk_to_translate == <t1_2000k/t1ab>
File not found or file cannot be opened.
Exit 255
ls: t6_2000k/t6ab: No such file or directory
Exit 1
is there anything wrong with my string $chunk_to_translate ? maybe any hidden chracter even though i didn't see it in echo
ASKER
--> ozo : here is the output
Speed 5149.01 KB/s
Wed Mar 21 18:09:14 PDT 2007
Wed Mar 21 18:09:15 PDT 2007
1 - t2aa
2 - t2ab
3 - t2ac
4 -
Enter chunk # to translate: 2
0000000 c h u n k _ t o _ t r a n s l a
0000020 t e = = < t 2 _ 2 0 0 0 k /
0000040 033 [ 0 0 m t 2 a b 033 [ 0 0 m > \n
0000060
File not found or file cannot be opened.
Exit 255
Speed 5149.01 KB/s
Wed Mar 21 18:09:14 PDT 2007
Wed Mar 21 18:09:15 PDT 2007
1 - t2aa
2 - t2ab
3 - t2ac
4 -
Enter chunk # to translate: 2
0000000 c h u n k _ t o _ t r a n s l a
0000020 t e = = < t 2 _ 2 0 0 0 k /
0000040 033 [ 0 0 m t 2 a b 033 [ 0 0 m > \n
0000060
File not found or file cannot be opened.
Exit 255
ASKER
is the "\n" throw me off ? if so, how do I get rid of it ?
I suspect the 033 [ 0 0 m may be be part of the problem
\n should not be problem, there is something weired in the beginning though.
ASKER
don't be alarmed by the prefix name such as "t1, t2, t3 ....etc"
I specified that name.
I specified that name.
Could you also do
ls t6_2000k | od -c
ls t6_2000k | od -c
ASKER
--> ozo : I agree with you. Where are those 033 [...etc comes from ? how to get rid of it ?
ASKER
--> amit_q : here is the result
Speed 5567.98 KB/s
Wed Mar 21 18:19:01 PDT 2007
Wed Mar 21 18:19:02 PDT 2007
1 - t3aa
2 - t3ab
3 - t3ac
4 -
Enter chunk # to translate: 2
0000000 c h u n k _ t o _ t r a n s l a
0000020 t e = = < t 3 _ 2 0 0 0 k /
0000040 033 [ 0 0 m t 3 a b 033 [ 0 0 m > \n
0000060
ls: t6_2000k: No such file or directory
0000000 033 [ 0 0 m 033 [ m E x i t 1 \n
0000017
Exit 1
File not found or file cannot be opened.
Exit 255
ls: t6_2000k/t6ab: No such file or directory
Speed 5567.98 KB/s
Wed Mar 21 18:19:01 PDT 2007
Wed Mar 21 18:19:02 PDT 2007
1 - t3aa
2 - t3ab
3 - t3ac
4 -
Enter chunk # to translate: 2
0000000 c h u n k _ t o _ t r a n s l a
0000020 t e = = < t 3 _ 2 0 0 0 k /
0000040 033 [ 0 0 m t 3 a b 033 [ 0 0 m > \n
0000060
ls: t6_2000k: No such file or directory
0000000 033 [ 0 0 m 033 [ m E x i t 1 \n
0000017
Exit 1
File not found or file cannot be opened.
Exit 255
ls: t6_2000k/t6ab: No such file or directory
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
can you show your
man ls
man ls
ASKER
--> ozo : you're absolutely right. it's the color that threw me off.
Brilliant !
thanks both of you for your time on this. Thanks to amit_q for pointing out the bug. I'll split the points.
Brilliant !
thanks both of you for your time on this. Thanks to amit_q for pointing out the bug. I'll split the points.
ASKER
for the record : I have my ls aliases to "ls-F --color"
That was a great catch ozo.
Add
unalias *
in the beginning of your script to remove all aliases for the script.
Add
unalias *
in the beginning of your script to remove all aliases for the script.
CreateFile
#Delay 5 seconds...
sleep 5
OpenFile