[SOLVED] Why would a command work from the command line but not within a script?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
fetches September 20's. I wrote a script to automate this (generate the date) but it doesn't work. I made sure the script creates the correct command (by echoing it instead of running it).
The same happens with Heng's comics. I fetch dozens of other comics with a script.
Did you set a crontab job? Maybe a path issue then
You should give a full path for Chappatte-20160920.jpeg, not sure if cron would save it in your home, /tmp or elsewhere
The script works for me but since I changed the paths it may not be a true test. For the systems (debian and CentOS) that I am working with at the moment lynx is located in /usr/bin.
It depends on how cron's environment is configured. For debian $HOME is set.
Are you running this as a cron job or just from the command line? If it does not work from the command line are there any errors?
[see 'Update' first...]
What's "not found"? (probably /usr/local/bin/lynx but it 'IS' there)
Try: sh -vx yourNYTscriptfilename
and/or put in, as 2nd line: (btw, what editor do you use? vi?)
set -vx
If you create [the 'SAME way'] a script with just a simple command like ls or df .
in it, does it work ok? [maybe; you mentioned other scripts work]
Try a script [*created the 'same way'*] with just: (omit 1st !# line [space was ok])
/usr/local/bin/lynx -version
Update:
I got it [MYscript, using /bin/ls in place of ...lynx] to say ONLY:
Quote:
/bin/ls: not found
by inserting a \r (ctrl-v ctrl-m in vi) in front of the command;
cat'ing the script looks 'ok', like post #8. (same for just ls)
Try: od -c yourNYTscriptfilename
and *carefully* look for \r or some other 'bad' character. (\n is 'good')
How [exactly] do you 'create' your 'nyt' scripts? (Microsoft 'does' \r)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.