if condition not working when run from crontab [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
-4
down vote
favorite
my requirement is if "Date" matches with the list of dates present in "file.txt", then it should say sucess "Date has matched".
#!/bin/bash
Date="Jun212018"
for i in `cat /home/file.txt`
do
if [ $i == $VT ]
then
echo "Date has Matched"
fi
done
shell cron
closed as unclear what you're asking by jasonwryan, roaima, Jeff Schaller, Kiwy, Thomas Nyman Jun 21 at 12:38
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
 |Â
show 3 more comments
up vote
-4
down vote
favorite
my requirement is if "Date" matches with the list of dates present in "file.txt", then it should say sucess "Date has matched".
#!/bin/bash
Date="Jun212018"
for i in `cat /home/file.txt`
do
if [ $i == $VT ]
then
echo "Date has Matched"
fi
done
shell cron
closed as unclear what you're asking by jasonwryan, roaima, Jeff Schaller, Kiwy, Thomas Nyman Jun 21 at 12:38
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
What's"$VT"
supposed to be?
â roaima
Jun 21 at 8:12
How are you executing this fromcron
? Are expectingDate has Matched
to be produced for each date infile.txt
that matches? What happens when you try to run this? What is$VT
?
â Kusalananda
Jun 21 at 8:12
what's the link to crontab ?
â Kiwy
Jun 21 at 8:12
2
^^ Update your question. Don't put updates in comments as they're much harder to read or even find
â roaima
Jun 21 at 8:18
2
"Update your question" does not mean "Open a new question" ...
â RoVo
Jun 21 at 8:58
 |Â
show 3 more comments
up vote
-4
down vote
favorite
up vote
-4
down vote
favorite
my requirement is if "Date" matches with the list of dates present in "file.txt", then it should say sucess "Date has matched".
#!/bin/bash
Date="Jun212018"
for i in `cat /home/file.txt`
do
if [ $i == $VT ]
then
echo "Date has Matched"
fi
done
shell cron
my requirement is if "Date" matches with the list of dates present in "file.txt", then it should say sucess "Date has matched".
#!/bin/bash
Date="Jun212018"
for i in `cat /home/file.txt`
do
if [ $i == $VT ]
then
echo "Date has Matched"
fi
done
shell cron
edited Jun 21 at 8:11
Kusalananda
101k13199312
101k13199312
asked Jun 21 at 8:10
user296431
1
1
closed as unclear what you're asking by jasonwryan, roaima, Jeff Schaller, Kiwy, Thomas Nyman Jun 21 at 12:38
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by jasonwryan, roaima, Jeff Schaller, Kiwy, Thomas Nyman Jun 21 at 12:38
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
What's"$VT"
supposed to be?
â roaima
Jun 21 at 8:12
How are you executing this fromcron
? Are expectingDate has Matched
to be produced for each date infile.txt
that matches? What happens when you try to run this? What is$VT
?
â Kusalananda
Jun 21 at 8:12
what's the link to crontab ?
â Kiwy
Jun 21 at 8:12
2
^^ Update your question. Don't put updates in comments as they're much harder to read or even find
â roaima
Jun 21 at 8:18
2
"Update your question" does not mean "Open a new question" ...
â RoVo
Jun 21 at 8:58
 |Â
show 3 more comments
1
What's"$VT"
supposed to be?
â roaima
Jun 21 at 8:12
How are you executing this fromcron
? Are expectingDate has Matched
to be produced for each date infile.txt
that matches? What happens when you try to run this? What is$VT
?
â Kusalananda
Jun 21 at 8:12
what's the link to crontab ?
â Kiwy
Jun 21 at 8:12
2
^^ Update your question. Don't put updates in comments as they're much harder to read or even find
â roaima
Jun 21 at 8:18
2
"Update your question" does not mean "Open a new question" ...
â RoVo
Jun 21 at 8:58
1
1
What's
"$VT"
supposed to be?â roaima
Jun 21 at 8:12
What's
"$VT"
supposed to be?â roaima
Jun 21 at 8:12
How are you executing this from
cron
? Are expecting Date has Matched
to be produced for each date in file.txt
that matches? What happens when you try to run this? What is $VT
?â Kusalananda
Jun 21 at 8:12
How are you executing this from
cron
? Are expecting Date has Matched
to be produced for each date in file.txt
that matches? What happens when you try to run this? What is $VT
?â Kusalananda
Jun 21 at 8:12
what's the link to crontab ?
â Kiwy
Jun 21 at 8:12
what's the link to crontab ?
â Kiwy
Jun 21 at 8:12
2
2
^^ Update your question. Don't put updates in comments as they're much harder to read or even find
â roaima
Jun 21 at 8:18
^^ Update your question. Don't put updates in comments as they're much harder to read or even find
â roaima
Jun 21 at 8:18
2
2
"Update your question" does not mean "Open a new question" ...
â RoVo
Jun 21 at 8:58
"Update your question" does not mean "Open a new question" ...
â RoVo
Jun 21 at 8:58
 |Â
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
Your script leaves VT
undefined (unless it's set in the environment, but that leaves Date
unused).
A simpler script:
#!/bin/sh
if grep -q -Fx 'Jun212018' /home/file.txt; then
echo 'Date has Matched'
fi
This prints the string if the date Jun212018
matches exactly on a single line in the file.
From comments below, it seem this is what you want to be doing:
#!/bin/sh
today=$( date +%b%d%Y )
if grep -q -Fx "$today" /home/file.txt; then
echo 'date has matched' >/home/otherfile
fi
i tried, this works fine from command line, but doesn't work from crontab
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:31
@user296431 So, what happens when you run fromcron
? Also, what is the point of the code you posted in your later comments? What is it that you want to say/do?
â Kusalananda
Jun 21 at 8:39
1
@user296431 What does "not working" mean? Do you get error messages? I can't see your screen from where I'm sitting, you know...
â Kusalananda
Jun 21 at 9:08
 |Â
show 4 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Your script leaves VT
undefined (unless it's set in the environment, but that leaves Date
unused).
A simpler script:
#!/bin/sh
if grep -q -Fx 'Jun212018' /home/file.txt; then
echo 'Date has Matched'
fi
This prints the string if the date Jun212018
matches exactly on a single line in the file.
From comments below, it seem this is what you want to be doing:
#!/bin/sh
today=$( date +%b%d%Y )
if grep -q -Fx "$today" /home/file.txt; then
echo 'date has matched' >/home/otherfile
fi
i tried, this works fine from command line, but doesn't work from crontab
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:31
@user296431 So, what happens when you run fromcron
? Also, what is the point of the code you posted in your later comments? What is it that you want to say/do?
â Kusalananda
Jun 21 at 8:39
1
@user296431 What does "not working" mean? Do you get error messages? I can't see your screen from where I'm sitting, you know...
â Kusalananda
Jun 21 at 9:08
 |Â
show 4 more comments
up vote
2
down vote
Your script leaves VT
undefined (unless it's set in the environment, but that leaves Date
unused).
A simpler script:
#!/bin/sh
if grep -q -Fx 'Jun212018' /home/file.txt; then
echo 'Date has Matched'
fi
This prints the string if the date Jun212018
matches exactly on a single line in the file.
From comments below, it seem this is what you want to be doing:
#!/bin/sh
today=$( date +%b%d%Y )
if grep -q -Fx "$today" /home/file.txt; then
echo 'date has matched' >/home/otherfile
fi
i tried, this works fine from command line, but doesn't work from crontab
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:31
@user296431 So, what happens when you run fromcron
? Also, what is the point of the code you posted in your later comments? What is it that you want to say/do?
â Kusalananda
Jun 21 at 8:39
1
@user296431 What does "not working" mean? Do you get error messages? I can't see your screen from where I'm sitting, you know...
â Kusalananda
Jun 21 at 9:08
 |Â
show 4 more comments
up vote
2
down vote
up vote
2
down vote
Your script leaves VT
undefined (unless it's set in the environment, but that leaves Date
unused).
A simpler script:
#!/bin/sh
if grep -q -Fx 'Jun212018' /home/file.txt; then
echo 'Date has Matched'
fi
This prints the string if the date Jun212018
matches exactly on a single line in the file.
From comments below, it seem this is what you want to be doing:
#!/bin/sh
today=$( date +%b%d%Y )
if grep -q -Fx "$today" /home/file.txt; then
echo 'date has matched' >/home/otherfile
fi
Your script leaves VT
undefined (unless it's set in the environment, but that leaves Date
unused).
A simpler script:
#!/bin/sh
if grep -q -Fx 'Jun212018' /home/file.txt; then
echo 'Date has Matched'
fi
This prints the string if the date Jun212018
matches exactly on a single line in the file.
From comments below, it seem this is what you want to be doing:
#!/bin/sh
today=$( date +%b%d%Y )
if grep -q -Fx "$today" /home/file.txt; then
echo 'date has matched' >/home/otherfile
fi
edited Jun 21 at 8:54
answered Jun 21 at 8:15
Kusalananda
101k13199312
101k13199312
i tried, this works fine from command line, but doesn't work from crontab
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:31
@user296431 So, what happens when you run fromcron
? Also, what is the point of the code you posted in your later comments? What is it that you want to say/do?
â Kusalananda
Jun 21 at 8:39
1
@user296431 What does "not working" mean? Do you get error messages? I can't see your screen from where I'm sitting, you know...
â Kusalananda
Jun 21 at 9:08
 |Â
show 4 more comments
i tried, this works fine from command line, but doesn't work from crontab
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:31
@user296431 So, what happens when you run fromcron
? Also, what is the point of the code you posted in your later comments? What is it that you want to say/do?
â Kusalananda
Jun 21 at 8:39
1
@user296431 What does "not working" mean? Do you get error messages? I can't see your screen from where I'm sitting, you know...
â Kusalananda
Jun 21 at 9:08
i tried, this works fine from command line, but doesn't work from crontab
â user296431
Jun 21 at 8:30
i tried, this works fine from command line, but doesn't work from crontab
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:30
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:31
if grep -q -Fx 'Jun212018' /home/file.txt; then touch file1.txt fi
â user296431
Jun 21 at 8:31
@user296431 So, what happens when you run from
cron
? Also, what is the point of the code you posted in your later comments? What is it that you want to say/do?â Kusalananda
Jun 21 at 8:39
@user296431 So, what happens when you run from
cron
? Also, what is the point of the code you posted in your later comments? What is it that you want to say/do?â Kusalananda
Jun 21 at 8:39
1
1
@user296431 What does "not working" mean? Do you get error messages? I can't see your screen from where I'm sitting, you know...
â Kusalananda
Jun 21 at 9:08
@user296431 What does "not working" mean? Do you get error messages? I can't see your screen from where I'm sitting, you know...
â Kusalananda
Jun 21 at 9:08
 |Â
show 4 more comments
1
What's
"$VT"
supposed to be?â roaima
Jun 21 at 8:12
How are you executing this from
cron
? Are expectingDate has Matched
to be produced for each date infile.txt
that matches? What happens when you try to run this? What is$VT
?â Kusalananda
Jun 21 at 8:12
what's the link to crontab ?
â Kiwy
Jun 21 at 8:12
2
^^ Update your question. Don't put updates in comments as they're much harder to read or even find
â roaima
Jun 21 at 8:18
2
"Update your question" does not mean "Open a new question" ...
â RoVo
Jun 21 at 8:58