showbix
asked on
Execute file without ./
Question 1
I have a directory called MYPROJ. Underneath it are 10 sub-directories. My problem is everytime I want to execute a file in any of the directory under MYPROJ, I have to type ./filename. How do I avoid typing ./ for all the 10 directories under MYPROJ.
Question 2
I have a file called amc.log. I want to delete the content of the file automatically every 3 days. How do I do that? Is there cron for that purpose?
I have a directory called MYPROJ. Underneath it are 10 sub-directories. My problem is everytime I want to execute a file in any of the directory under MYPROJ, I have to type ./filename. How do I avoid typing ./ for all the 10 directories under MYPROJ.
Question 2
I have a file called amc.log. I want to delete the content of the file automatically every 3 days. How do I do that? Is there cron for that purpose?
ASKER
Hi ahoffmann.
Question 1 : Any short way instead of defining one directory after another?
Question 2 : Any idea?
Question 1 : Any short way instead of defining one directory after another?
Question 2 : Any idea?
1)
cd MYPROJ
for file in *
do
if [ -d $file ]
then
export PATH=$PATH:$file
fi
done
You may need to also test that the directory is not "." or ".."
if you put this in a script you would need to execute it like this :-
. ./env_script to include the definition of PATH in the current shell.
2) Yes cron could be used for this. THe only problem is you want to delete every 3 days I can't think of an easy way of doing this other than within a script. Cron defines five time fields for controlling when the job is run :-
minute
hour
day of month
month
day of week
so if you ignored Sunday for example you could execute your delete on monday and thursday using
0 0 * * 1,4 rm -f /path/to/log/amc.log.
This would remove the file at midnight on monday and thursday. If it has to be strictly every three days then you would need to add the day logic to a script and execute the script every day. The script can then decide itself whether or not to delete the file. The crontab enrty would then be :-
0 0 * * * /path/to/my_delete_script. sh
Hope this helps
cd MYPROJ
for file in *
do
if [ -d $file ]
then
export PATH=$PATH:$file
fi
done
You may need to also test that the directory is not "." or ".."
if you put this in a script you would need to execute it like this :-
. ./env_script to include the definition of PATH in the current shell.
2) Yes cron could be used for this. THe only problem is you want to delete every 3 days I can't think of an easy way of doing this other than within a script. Cron defines five time fields for controlling when the job is run :-
minute
hour
day of month
month
day of week
so if you ignored Sunday for example you could execute your delete on monday and thursday using
0 0 * * 1,4 rm -f /path/to/log/amc.log.
This would remove the file at midnight on monday and thursday. If it has to be strictly every three days then you would need to add the day logic to a script and execute the script every day. The script can then decide itself whether or not to delete the file. The crontab enrty would then be :-
0 0 * * * /path/to/my_delete_script.
Hope this helps
> Question 1 : Any short way instead of defining one directory after another?
put your programs in one directory, or use a loop as suggested
> Q1:
cron, see example above
put your programs in one directory, or use a loop as suggested
> Q1:
cron, see example above
Hi,
You can add a "." to your PATH environment variable.
try this test:
export PATH=$PATH:.
cd MYPROJ
filename
cd some-sub-dir
filename
if both executions of filename worked fine so you can put the line "export PATH=$PATH:." into your .profile
good luck
You can add a "." to your PATH environment variable.
try this test:
export PATH=$PATH:.
cd MYPROJ
filename
cd some-sub-dir
filename
if both executions of filename worked fine so you can put the line "export PATH=$PATH:." into your .profile
good luck
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
2) Instead of deleting the log, use cron to "age" it on a daily basis, so you always have a couple of days history, e.g.
cp amc.log.old amv.log.older
cp amc.log amc.log.old # This may barf if amc.log is constantly changing
cat /dev/null > amc.log
Plus this is much simpler than doing date calculations...
cp amc.log.old amv.log.older
cp amc.log amc.log.old # This may barf if amc.log is constantly changing
cat /dev/null > amc.log
Plus this is much simpler than doing date calculations...
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:
- Answered by bedot
Please leave any comments here within the next 7 days
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
tfewster
Cleanup Volunteer
I will leave a recommendation for this question in the Cleanup topic area as follows:
- Answered by bedot
Please leave any comments here within the next 7 days
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
tfewster
Cleanup Volunteer
per recommendation
SpideyMod
Community Support Moderator @Experts Exchange
SpideyMod
Community Support Moderator @Experts Exchange
add MYPROJ and MYPROJ/sub1 and ... MYPROJ/sub10 to your PATH environment variable, like:
PATH="$PATH":MYPROJ:MYPROJ
or in csh:
setenv PATH "$PATH":MYPROJ:MYPROJ/sub1