if condition not working when run from crontab [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash 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






share|improve this 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 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






  • 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














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






share|improve this 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 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






  • 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












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






share|improve this question













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








share|improve this question












share|improve this question




share|improve this question








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 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






  • 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




    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











  • 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










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





share|improve this answer























  • 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 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




    @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

















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





share|improve this answer























  • 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 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




    @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














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





share|improve this answer























  • 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 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




    @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












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





share|improve this answer















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






share|improve this answer















share|improve this answer



share|improve this answer








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 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




    @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










  • 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 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




    @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


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?