Csh/tcsh : Check the file existance and run the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Csh/tcsh : Check the file existance and run the script
# 1  
Old 02-09-2014
Csh/tcsh : Check the file existance and run the script

Hi,
I've to wait until a file generated and once its generated, source another script in Linux terminal.

Please help me as this is very very urgent.

The code should be something like
Code:
if ( -e "/abc/xyz/a.txt )
   source aaa.csh
else
   sleep

This should be repeated till the if condition is met.

Rgds,
Kumar

Last edited by Neo; 02-09-2014 at 02:24 PM.. Reason: please use code tags for code, data,etc (it's a rule of the forum)
# 2  
Old 02-09-2014
That's all you have tried so far?

I think you should show more effort into trying different things.

That's your entire effort at this script (posting code with syntax errors - i.e. unmatched double quotes)?
# 3  
Old 02-09-2014
Dear Neo,
I tried the following piece of code.

Code:
#!/bin/csh -f
set ctrl = 1;
while ( $ctrl != 0 )
   if ( -e t ) then
      source aaa.csh
      set ctrl = 0;
   else
      echo "File Not Found : Sleeping"
      sleep 10
   endif
end


I feel its solving my purpose, just wanted to confirm with experts.

Last edited by kumar_eee; 02-09-2014 at 02:31 PM.. Reason: please use code tags (second request)
# 4  
Old 02-09-2014
OK. thanks for posting.. we have a lot of shell experts here to give you ideas (I'm more of a PHP guy these days)..... be patient and someone will reply to you.
# 5  
Old 02-09-2014
I am not csh programmer. I use ksh or bash for everything. But I'll take a stab at this. The only thing I see with the script is the superfluous but harmless semi-colons on those set statements. But I would code it differently to simplify the script...

Code:
#! /bin/csh -f

while ( ! -e somefile )
        echo file not found -- sleeping
        sleep 10
end
source file2
exit 0

and then a test run...

Code:
$ ./sleeper
file not found -- sleeping
file not found -- sleeping
file not found -- sleeping
hello
I am file2
$

In another window I typed "touch somefile" to get out of the loop.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

check for file existance and generate exit code amd move to another directory

Hi.. i have a file ABC_*.txt in source directory which will come evry 30 min and same file will be moved to working directory first time ...and will perform some operations then we archive ABC_*.txt ..this will run for 30 min to 45 min from 2nd time onwards requirement is ...i need to check... (3 Replies)
Discussion started by: dssyadav
3 Replies

2. Shell Programming and Scripting

How to run a file in a csh script?

Hi, I have a csh script. I want to set some variables and execute some command from a file in that script. abc.csh echo "primary script" b setenv XXX ddd set XX make abc I want to execute the commands of "b" file from abc.csh. How can i do that. Please view this link: How to use... (3 Replies)
Discussion started by: vdhingra123
3 Replies

3. Shell Programming and Scripting

how to check existance of multiple directories

Hi, I would like to check whether all the directories exists or not. I tried the below but it gives some error. below is the excerpt from my original script 24 #Check if the required directories are exists 25 dirExists() { 26 27 if 28 then 29 echo "required... (1 Reply)
Discussion started by: lookinginfo
1 Replies

4. Shell Programming and Scripting

Scripting to check the size of file and it's existance.

Hi, I am totaly new to create a script . Please help. I have file name retrived from SAP table into a internal table . Like :- /home/td_8d02_int_data_IPCL/ILLUSTRATIONS/CGM/l_pc_112138_01_0_01_00.cgm /home/td_8d02_int_data_IPC-L/ILLUSTRATIONS/CMP/l_pc_112138_01_0_01_00.cmp Objective... (1 Reply)
Discussion started by: amitkumar.b2
1 Replies

5. Shell Programming and Scripting

How to run a bash script in csh shell?

Hi how to execute a bash script in csh shell? Thanks (3 Replies)
Discussion started by: rubinovito
3 Replies

6. Shell Programming and Scripting

tcsh: not run script (if: Badly formed number)

Hello I have Linux Debian & tcsh shell. My mini script not run :(. Startup script displays a message: user@host:dir% ./test if: Badly formed number. script: #!/bin/tcsh -f #script check size files systems set x = `df -h /usr | tail -n1 | awk '{ print( $5 ); }'` set y = 60% if ($x... (5 Replies)
Discussion started by: moskovets
5 Replies

7. Shell Programming and Scripting

check the file existance

Hello, I have two files .. 1. inventory_i.txt 2. inventory_b.txt I want to check if these two files exists. If exists, then do the process, otherwise, quite... if ; then echo "exists" else echo " does not exists" fi The above logic is not working... It is always, displaying Does... (2 Replies)
Discussion started by: govindts
2 Replies

8. Shell Programming and Scripting

Differences between csh and tcsh

What are the differences between csh and tcsh shells ? In one of the shell scripts csh binary is a soft link to tcsh. (1 Reply)
Discussion started by: shafi2all
1 Replies

9. Shell Programming and Scripting

Unexpected end of file..with csh->tcsh

All; Thanks for reading. I'm having a heck of a time with this cshell script that fires off an hp temperature monitor and rotates logs. I keep getting '/opt/temperature/temp.sh: line 22: syntax error: unexpected end of file' when I try to 'sh /opt/temperature/temp.sh" it --script... (3 Replies)
Discussion started by: swjv
3 Replies

10. UNIX for Dummies Questions & Answers

diff between tcsh and csh -f

Hello Am very new to linux/unix, workin in it since 10 days only. I had started with bash and now I need to work in tcsh. I have changed shell for my user profile using 'chsh' I use gedit for script writing. Now in the first line if I write #!/bin/tcsh i get d msg /home/usr/.cshrc: No such... (2 Replies)
Discussion started by: mahendrakamath
2 Replies
Login or Register to Ask a Question