Operating System - Tru64 Unix
cancel
Showing results for 
Search instead for 
Did you mean: 

batch file execution

fergani
Advisor

batch file execution

Hi everyone,
I create a batch file and also create file is called FAIMOS for database.
The batch file is executed automatically at start-up ,so I want it to be executed ONLY when the du of the FAIMOS is ZERO.

What could I add to the batch file in order to meet my requirement?
I know only how to get the batch file executed at start-up.
bye.
9 REPLIES
Steven Schweda
Honored Contributor

Re: batch file execution

man test

Look for "-s".
fergani
Advisor

Re: batch file execution

Hi
I have two directories the first one is called faimos and it has some data,
and the other is called fiims and it is empty.

I made two batch files are called startup_1 and startup_2.
The first batch file (startup_1) is contained the following :-
-----------------------
vi startup_1
dir1=/faimos
if test -s "$dir1" then
echo the faimos directory has some data
fi
---------------------------

And the second batch file is contained the following :-
----------------------------
vi startup_2
dir2=/fiims
if test -s "$dir2" then
echo the faimos directory is empty
fi
------------------------------
the results when I executed the first and the second batch file are shown bellow:-

--------------------
sh startup_1
the faimos directory has some data
--------------------
sh startup_2
the faimos directory is empty
--------------------
I think the first result is true, but the second result is wrong the message should not be appeared because the fiims directory is empty and If statement return false.

please could you help me to solve my problem?
Steven Schweda
Honored Contributor

Re: batch file execution

> please could you help me to solve my
> problem?

Perhaps, if you first decide what it is.

> [...] create file is called FAIMOS [...]

> [...] two directories the first one is
> called faimos [...]

If it's a file, then "test -s" should work.
If it's a directory, then you may need to do
more work.

> [...] when the du of the FAIMOS is ZERO.

What, exactly, is the condition you wish to
test? "du" says zero, or no files in the
directory, or what?

urtx# mkdir empty_directory
urtx# du -k empty_directory
8 empty_directory

It's not easy to get "du" to say zero. Even
an empty directory occupies some disk space.

urtx# mkdir non-empty_directory
urtx# echo fred > non-empty_directory/small_file

urtx# ls -1A empty_directory
urtx# ls -1A non-empty_directory
small_file

urtx# ls -1A empty_directory | wc -l
0
urtx# ls -1A non-empty_directory | wc -l
1

urtx# find empty_directory
empty_directory
urtx# find non-empty_directory
non-empty_directory
non-empty_directory/small_file

"wc -l" could count those, too.

urtx# find empty_directory | grep '/'
urtx# echo $?
1

urtx# find non-empty_directory | grep '/'
non-empty_directory/small_file
urtx# echo $?
0

"grep -q" would be quieter:

urtx# find empty_directory | grep -q '/'
urtx# echo $?
1
urtx# find non-empty_directory | grep -q '/'
urtx# echo $?
0


As usual, many things are possible.
Steven Schweda
Honored Contributor

Re: batch file execution

> if test -s "$dir1" then

That works without a semi-colon? I'd say:

if test -s "$dir1"; then


dir1=/faimos
if test -s "$dir1" then
echo the faimos directory has some data

dir2=/fiims
if test -s "$dir2" then
echo the faimos directory is empty

This stuff is not magic. Changing the
message does not change the meaning of
"test -s". "test" does offer this:

! Unary negation operator.

and _that_ does work.
fergani
Advisor

Re: batch file execution

Hi Steven Schweda,

The condition I wish to
test? "du" says zero in the
directory, pleas could you provide me with complete syntax for if statement.

Bye.
Steven Schweda
Honored Contributor

Re: batch file execution

> The condition I wish to
> test? "du" says zero in the
> directory

Are you not reading this stuff? As I've
showed, "du" does not say zero for an empty
directory. Does your "du" work differently
from mine?

> pleas could you provide me with complete
> syntax for if statement.

You're not paying me enough to get me to do
your whole job for you. I've already offered
a few different methods which should work.
fergani
Advisor

Re: batch file execution

Hi Steven Schweda:-
You're not paying me enough to get me to do
your whole job for you.

The exact and the whole job I intend to do with described details is:-

I create a batch file is called at_startup and also create a directory is called Faimos for database.
The batch file is executed automatically at start-up and contains the following:-

vi at_startup
LOGFILE=/usr/backup/logfile; export LOGFILE
date >>$LOGFILE 2>>$LOGFILE
TAPE=/dev/ntape/tape0c
su - oracle -c /usr/backup/dbshut >>$LOGFILE 2>>$LOGFILE
cd /
tar -xvf $TAPE faimos
find /faimos -name '*.dump' -exec rm {} \;
su - oracle -c /usr/backup/dbstart >>$LOGFILE 2>>$LOGFILE
su - oracle -c "sqlplus system/manager @/alt_fa_user.sql"


but I need this batch file to be executed only when Faimos directory is empty

bye.
Steven Schweda
Honored Contributor

Re: batch file execution

> [...] I've already offered
> a few different methods which should work.

Still true.
fergani
Advisor

Re: batch file execution

I used test -d instead of -s