There are 2 ip address where I want to add a job to cron which runs at 7am daily.
In one place the cron job runs everyday and in the other it runs only on the 1st of month.
Instead of setting up 2 different cron jobs can this be done in a single script?
Eg.
1.
<code> if [ -e "$file_path" ]; then
echo "File '$file_path' exists"
while read -r line
do
${line}
done< "$file_path"
else
echo "File '$file_path' does not exist"
fi
</code>
<code> if [ -e "$file_path" ]; then
echo "File '$file_path' exists"
while read -r line
do
${line}
done< "$file_path"
else
echo "File '$file_path' does not exist"
fi
</code>
if [ -e "$file_path" ]; then
echo "File '$file_path' exists"
while read -r line
do
${line}
done< "$file_path"
else
echo "File '$file_path' does not exist"
fi
-
<code> current_day=$(date +%d)echo "today: '$current_day'"if [ "$current_day" -eq 01 ]; thenif [ -e "$file_path" ]; thenecho "File '$file_path' exists"while read -r linedo${line}done< "$file_path"elseecho "File '$file_path' does not exist"fielseecho "Today is not the first day of the month."fi</code><code> current_day=$(date +%d) echo "today: '$current_day'" if [ "$current_day" -eq 01 ]; then if [ -e "$file_path" ]; then echo "File '$file_path' exists" while read -r line do ${line} done< "$file_path" else echo "File '$file_path' does not exist" fi else echo "Today is not the first day of the month." fi </code>
current_day=$(date +%d) echo "today: '$current_day'" if [ "$current_day" -eq 01 ]; then if [ -e "$file_path" ]; then echo "File '$file_path' exists" while read -r line do ${line} done< "$file_path" else echo "File '$file_path' does not exist" fi else echo "Today is not the first day of the month." fi
eg. Contents of file_path:
<code> echo 'test'
</code>
<code> echo 'test'
</code>
echo 'test'
Or is it possible to have contents of the file path similar to
<code> if [ $(date '+%d') -eq 27 ]; then; echo 'today' fi
</code>
<code> if [ $(date '+%d') -eq 27 ]; then; echo 'today' fi
</code>
if [ $(date '+%d') -eq 27 ]; then; echo 'today' fi
The above does not work as the cronjob is looking for a command instead of a condition.
Any help would be appreciated.