Error 1 In Running Shell Script
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you
Running Linux Shell Script
might have Meta Discuss the workings and policies of this site running korn shell script About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting
Running Shell Script In Python
ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of running shell script from php Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Shell script throws a not found error when run from a sh file. But if entered manually running shell script in background the commands work up vote 7 down vote favorite 3 I'm trying to use the following script to generate a sitemap for my website. When I run it as sh thsitemap.sh I get an error like this and creates an empty sitemap.xml file: thsitemap.sh: 22: thsitemap.sh: [[: not found thsitemap.sh: 42: thsitemap.sh: [[: not found thsitemap.sh: 50: thsitemap.sh: Syntax error: "(" unexpected But as the same user root when I manually copy and paste these lines on the terminal, it works without any error and the sitemap.xml file have all the urls. What's the problem? How can I fix this? #!/bin/bash ############################################## # modified version of original http://media-glass.es/ghost-sitemaps/ # for ghost.centminmod.com # http://ghost.centminmod.com/ghost-sitemap-generator/ ############################################## url="techhamlet.com" webroot='/home/leafh8kfns/techhamlet.com' path="${webroot}/sitemap.xml" user='leafh8kfns' # web server user group='leafh8kfns' # web server group debug='n' # disable debug mode with debug='n' ############################################## date=`date +'%FT%k:%M:%S+00:00'` freq="daily" prio="0.5" reject='.rss, .gif, .png, .jpg, .css, .js, .txt, .ico, .eot, .woff, .ttf, .svg, .txt' ############################################## # create sitemap.xml file if it doesn't exist and give it same permissions
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the
Running Shell Script Mac
workings and policies of this site About Us Learn more about Stack running shell script in cygwin Overflow the company Business Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags
Running Shell Script In Debug Mode
Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it http://unix.stackexchange.com/questions/155838/shell-script-throws-a-not-found-error-when-run-from-a-sh-file-but-if-entered-ma only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Shell script error (: not found [No such file or directory]) [duplicate] up vote 4 down vote favorite 1 This question already has an answer here: Shell script works when saved with http://unix.stackexchange.com/questions/224187/shell-script-error-not-found-no-such-file-or-directory nano but not when saved with Notepad++ 2 answers I'm using following script on linux server. And which is giving: : not found [No such file or directory] This is the script: # ------------------------------------------------------------------ # K.Sugunan Host health check # Description # # This script to initiate health check on servers. # It will check for CPU, memory and some connectivity with # up stream and down stream system. # # ------------------------------------------------------------------ # Applying initial variables and loading config parameters DOCROOT=$(pwd)"/" TIME_NOW=$(date +"%Y-%m-%d %H:%M:%S") echo $DOCROOT . $DOCROOT"config/main.sh" . $DOCROOT"config/web.sh" . $DOCROOT"config/telnet.sh" echo $CPU_A The error will be like follows: : not found [No such file or directory] : not found [No such file or directory] /home/sugunan/phobos/ : not found [No such file or directory] : cannot open [No such file or directory]os/ I use following ways to run the script ksh poc.sh sh poc.sh ./poc.sh All of the above giving similar error. Even I include #!/bin/bash still the error exist. I have tried #!/bin/ksh and #!/usr/bin/ksh also. All of that gives the error. What may be the reason for the issu
and Signals and Traps (Oh My!) - Part 1 by William Shotts, Jr. In this lesson, we're going to look at handling errors during the execution of your scripts. http://linuxcommand.org/wss0150.php The difference between a good program and a poor one is often measured http://stackoverflow.com/questions/27138946/error-in-running-shell-script-while-loop in terms of the program's robustness. That is, the program's ability to handle situations in which something goes wrong. Exit status As you recall from previous lessons, every well-written program returns an exit status when it finishes. If a program finishes successfully, the exit status will be zero. If shell script the exit status is anything other than zero, then the program failed in some way. It is very important to check the exit status of programs you call in your scripts. It is also important that your scripts return a meaningful exit status when they finish. I once had a Unix system administrator who wrote a script for a production system running shell script containing the following 2 lines of code: # Example of a really bad idea cd $some_directory rm * Why is this such a bad way of doing it? It's not, if nothing goes wrong. The two lines change the working directory to the name contained in $some_directory and delete the files in that directory. That's the intended behavior. But what happens if the directory named in $some_directory doesn't exist? In that case, the cd command will fail and the script executes the rm command on the current working directory. Not the intended behavior! By the way, my hapless system administrator's script suffered this very failure and it destroyed a large portion of an important production system. Don't let this happen to you! The problem with the script was that it did not check the exit status of the cd command before proceeding with the rm command. Checking the exit status There are several ways you can get and respond to the exit status of a program. First, you can examine the contents of the $? environment variable. $? will contain the exit st
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error in running shell script while loop up vote 0 down vote favorite I wrote this shellscript file. But I get error near unexpected tokendone'` #!/bin/bash i=1 while [ $i -lt 12 ]; do echo Hi i=$[$i+1] done Previously, there was no ; before do. I read stackexchange answers and wrote ; after while [], still I get error. I could not found the resolution online. Any ideas? linux shell unix share|improve this question edited Nov 25 '14 at 23:56 asked Nov 25 '14 at 23:49 b2850624 85 Are you sure your script is run by bash? If you are executing it with sh myscript, and sh isn't a link to bash, your script is being run by some other shell (probably dash) which doesn't support bash's ancient $[...] syntax. –chepner Nov 26 '14 at 18:29 add a comment| 4 Answers 4 active oldest votes up vote 1 down vote i=$[$i+1] this is wrong. You probably meant i=$((i+1)) share|improve this answer answered Nov 25 '14 at 23:56 Jakub Kotowski 5,1951227 1 It's not so much wrong as antiquated and undocumented. $[...] was the bash notation for arithmetic expressions before POSIX $((...)) was adopted. –chepner Nov 26 '14 at 18:28 ah, nice, I didn't know –Jakub Kotowski Nov 26 '14 at 21:43 add a comment| up vote 0 down vote path to bash is incorrect, you have missed a root in path change first line to #!/bin/bash share|improve this answer answered Nov 25 '14 at 23:56 neveragny 236 fixed that. But still I have problem –b2850624 Nov 26 '14 at 0:03 add a comment| up vote 0 down vote Correct placement of ; in a bash script can be tricky indeed. Here's a one-liner version of your script with semicolons in the right place: i=1; while (( i < 12 )); do echo "Hi"; (( i++ )); done Note that the $ in variables becomes redundant for integer comparisons if placed between double parentheses (( )). share|improve this answer answered Nov 26 '14 at 7:46 user2243670 726 add a comment| up vote 0 down vote