<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Cron Schedule in Linux - issue with newline character in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798463#M59863</link>
    <description>The shell that we use is KSH. &lt;BR /&gt;&lt;BR /&gt;command: ps -p $$ -o args=&lt;BR /&gt;output : -ksh&lt;BR /&gt;--------------------------------&lt;BR /&gt;Command : (($(id -u)!=0)) &amp;amp;&amp;amp; echo "we aren't root" &amp;amp;&amp;amp; shopt -p xpg_echo&lt;BR /&gt;Output : we aren't root&lt;BR /&gt;-ksh: shopt: cannot execute [Permission denied]&lt;BR /&gt;--------------------------------&lt;BR /&gt;</description>
    <pubDate>Thu, 16 Jun 2011 07:42:10 GMT</pubDate>
    <dc:creator>sathis kumar</dc:creator>
    <dc:date>2011-06-16T07:42:10Z</dc:date>
    <item>
      <title>Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798456#M59856</link>
      <description>we have one simple script that works fine as expected while running it manually. However, it does not work the way it should be when scheduled through CRON. Script:&lt;BR /&gt;a="Perform"&lt;BR /&gt;b="Test"&lt;BR /&gt;output="$a\n$b\n"&lt;BR /&gt;echo "$output"&lt;BR /&gt;&lt;BR /&gt;while executing the above script, it should print the values of a and b in two lines. However, when scheduled through CRON it gives the following output: &lt;BR /&gt;"Perform\nTest\n".&lt;BR /&gt;&lt;BR /&gt;Could you please tell how we can get rid of this newline character issue (while using through CRON) ?&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Jun 2011 08:09:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798456#M59856</guid>
      <dc:creator>sathis kumar</dc:creator>
      <dc:date>2011-06-14T08:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798457#M59857</link>
      <description>&lt;!--!*#--&gt;&amp;gt; we have one simple script [...]&lt;BR /&gt;&lt;BR /&gt;Perhaps too simple.  Where's the "#!/bin/sh"&lt;BR /&gt;(or "#!&lt;WHICHEVER shell=""&gt;") line at the&lt;BR /&gt;beginning of this script?  Without it, you&lt;BR /&gt;don't know which shell you're using, and you&lt;BR /&gt;don't know which "echo" you're using.  It&lt;BR /&gt;might be a shell built-in "echo" or some&lt;BR /&gt;"echo" program on your PATH, and not every&lt;BR /&gt;"echo" works the same as every other "echo".&lt;BR /&gt;&lt;BR /&gt;Then, as a Forum search for "cron" should&lt;BR /&gt;make very clear, the environment in a "cron"&lt;BR /&gt;job may be very different from your&lt;BR /&gt;interactive environment.&lt;BR /&gt;&lt;BR /&gt;If you avoid any shell built-in "echo" by&lt;BR /&gt;changing "echo" to, say, "/bin/echo", then&lt;BR /&gt;you should be able to get the same behavior&lt;BR /&gt;in both cases.  (It may be not what you want&lt;BR /&gt;in both cases, but it should be the same.)&lt;BR /&gt;&lt;BR /&gt;      man echo&lt;BR /&gt;      man &lt;YOUR shell=""&gt;&lt;/YOUR&gt;&lt;/WHICHEVER&gt;</description>
      <pubDate>Tue, 14 Jun 2011 11:53:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798457#M59857</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2011-06-14T11:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798458#M59858</link>
      <description>echo -e "$output"</description>
      <pubDate>Tue, 14 Jun 2011 21:59:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798458#M59858</guid>
      <dc:creator>Wilfred Chau_1</dc:creator>
      <dc:date>2011-06-14T21:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798459#M59859</link>
      <description>First of all it depends on the shells you are using.&lt;BR /&gt;Since under most Linux distros bash is the default (unlike e.g. in the Grml distro which uses zsh as default) I suspect that in your usual login shell, which I assume to be a bash, you possibly have set the shell option xpg_echo.&lt;BR /&gt;You can easily check. If you type this&lt;BR /&gt;&lt;BR /&gt;$ shopt -p xpg_echo&lt;BR /&gt;shopt -u xpg_echo&lt;BR /&gt;&lt;BR /&gt;your output unlike mine most likely would read an "-s" (as "set") instead of an "-u".&lt;BR /&gt;See the effect if I set it.&lt;BR /&gt;&lt;BR /&gt;$ msg="See if our\tshell\nhonours escape sequences"&lt;BR /&gt;$ echo $msg&lt;BR /&gt;See if our\tshell\nhonours escape sequences&lt;BR /&gt;$ (shopt -s xpg_echo; echo $msg)&lt;BR /&gt;See if our      shell&lt;BR /&gt;honours escape sequences&lt;BR /&gt;$ unset msg&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;When your script is run under cron it most likely hasn't set the xpg_echo bash option.&lt;BR /&gt;Hence the difference.&lt;BR /&gt;&lt;BR /&gt;Then with the echo command you have to distinguish between the shell built-in (see man builtin, and search for echo) and the "external" command to which the echo manpage refers and which resides in /bin/echo.&lt;BR /&gt;Usually for performance sake it is desirable to have shell built-ins executed in favour of externals, which the shell does if not told otherwise (e.g. by prepending the full path to the external command).&lt;BR /&gt;On the other hand you can enforce execution of a built-in by issuing e.g. "builtin echo blabla".&lt;BR /&gt;&lt;BR /&gt;Besides, you can avoid the whole echo mess if you replace your echo statements by the (not built-in) printf statement.&lt;BR /&gt;But remember that printf doesn't do an automatic newline, just like the GNU/Linux/Bash echo command, and that you always need to provide a "\n" in the printf format string (see man printf).&lt;BR /&gt;This may slightly impair your performance depending on the amount of output your script generates though.&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Jun 2011 06:55:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798459#M59859</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2011-06-15T06:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798460#M59860</link>
      <description>Oops, didn't know this.&lt;BR /&gt;Just found in the builtin manpage a reference to printf as well.&lt;BR /&gt;So you needn't worry about performance issues if you stick to printf.&lt;BR /&gt;&lt;BR /&gt;Also, the tabstop in my xpg_echo example fell prey to the forum's site rendering (because I forgot to check "Retain format spacing" before submitting.</description>
      <pubDate>Wed, 15 Jun 2011 07:03:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798460#M59860</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2011-06-15T07:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798461#M59861</link>
      <description>shopt -p xpg_echo - getting permission denied message to run this.&lt;BR /&gt;&lt;BR /&gt;executed the script:&lt;BR /&gt;----------------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;a="Perform"&lt;BR /&gt;b="Test"&lt;BR /&gt;output="$a\n$b\n"&lt;BR /&gt;/bin/echo "$output"&lt;BR /&gt;&lt;BR /&gt;However, it gives the same output: &lt;BR /&gt;"Perform\nTest\n"&lt;BR /&gt;&lt;BR /&gt;Expected result is:&lt;BR /&gt;--------------------&lt;BR /&gt;Perform&lt;BR /&gt;Test&lt;BR /&gt;&lt;BR /&gt;Could you please let me know why the \n(newline character) is NOT getting recognized while running it through CRON?</description>
      <pubDate>Wed, 15 Jun 2011 09:50:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798461#M59861</guid>
      <dc:creator>sathis kumar</dc:creator>
      <dc:date>2011-06-15T09:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798462#M59862</link>
      <description>&amp;gt; shopt -p xpg_echo - getting permission denied message to run this.&lt;BR /&gt;&lt;BR /&gt;This is curious because issuing shopt normally doesn't require elevated privileges.&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;$ (($(id -u)!=0)) &amp;amp;&amp;amp; echo "we aren't root" &amp;amp;&amp;amp; shopt -p xpg_echo&lt;BR /&gt;we aren't root&lt;BR /&gt;shopt -u xpg_echo&lt;BR /&gt;&lt;BR /&gt;Are you sure your account uses a bash?&lt;BR /&gt;&lt;BR /&gt;What are the following outputting in your shell?&lt;BR /&gt;&lt;BR /&gt;$ ps -p $$ -o args=&lt;BR /&gt;-bash&lt;BR /&gt;&lt;BR /&gt;$ echo $-&lt;BR /&gt;himBH&lt;BR /&gt;&lt;BR /&gt;$ echo $BASH_VERSION&lt;BR /&gt;3.2.25(1)-release&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;As Wilfred already replied normally you need to pass your echo commands the "-e" option to make them expand backslash escapes.&lt;BR /&gt;&lt;BR /&gt;e.g. $ echo -e $output&lt;BR /&gt;&lt;BR /&gt;The whole shopt stuff was only an assumption on my behalf to explain why backslash escapes without providing the -e option to echo get expended nevertheless.&lt;BR /&gt;&lt;BR /&gt;Maybe someone has set an alias or a func in your user's .bashrc or in /etc/bashrc.&lt;BR /&gt;Check if you get a match when issuing&lt;BR /&gt;&lt;BR /&gt;$ alias echo&lt;BR /&gt;&lt;BR /&gt;or &lt;BR /&gt;&lt;BR /&gt;$ declare -f echo&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Jun 2011 06:04:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798462#M59862</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2011-06-16T06:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798463#M59863</link>
      <description>The shell that we use is KSH. &lt;BR /&gt;&lt;BR /&gt;command: ps -p $$ -o args=&lt;BR /&gt;output : -ksh&lt;BR /&gt;--------------------------------&lt;BR /&gt;Command : (($(id -u)!=0)) &amp;amp;&amp;amp; echo "we aren't root" &amp;amp;&amp;amp; shopt -p xpg_echo&lt;BR /&gt;Output : we aren't root&lt;BR /&gt;-ksh: shopt: cannot execute [Permission denied]&lt;BR /&gt;--------------------------------&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Jun 2011 07:42:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798463#M59863</guid>
      <dc:creator>sathis kumar</dc:creator>
      <dc:date>2011-06-16T07:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798464#M59864</link>
      <description>&lt;!--!*#--&gt;You aren't running a Bash.&lt;BR /&gt;So we could have saved a lot of guessing.&lt;BR /&gt;&lt;BR /&gt;In man ksh on RHEL I found this entry:&lt;BR /&gt;&lt;BR /&gt;       echo [ arg ... ]&lt;BR /&gt;              When  the  first  arg  does  not begin with a -, and none of the&lt;BR /&gt;              arguments contain a \, then echo prints each  of  its  arguments&lt;BR /&gt;              separated  by  a space and terminated by a new-line.  Otherwise,&lt;BR /&gt;              the behavior of echo is system dependent  and  print  or  printf&lt;BR /&gt;              described  below  should  be  used.   See  echo(1) for usage and&lt;BR /&gt;              description.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So if the string in arg does contain backslashes the behaviour of echo is system dependant (and printf should be used ;-)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;In man 5 crontab I found this entry:&lt;BR /&gt;&lt;BR /&gt;       Several  environment  variables are set up automatically by the cron(8)&lt;BR /&gt;       daemon.  SHELL is set to /bin/sh, and LOGNAME and HOME are set from the&lt;BR /&gt;       /etc/passwd  line  of the crontabÃ Â´s owner.  HOME and SHELL may be over-&lt;BR /&gt;       ridden by settings in the crontab; LOGNAME may not.&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;and a little further down&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;       The  "sixth"  field  (the rest of the line) specifies the command to be&lt;BR /&gt;       run.  The entire command portion of the line, up  to  a  newline  or  %&lt;BR /&gt;       character, will be executed by /bin/sh or by the shell specified in the&lt;BR /&gt;       SHELL variable of the cronfile.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So there you have it. cron excutes command under /bin/sh (if not told otherwise by the SHELL env var) which on Linux is a symlink to /bin/bash.&lt;BR /&gt;&lt;BR /&gt;$ ll /bin/sh&lt;BR /&gt;lrwxrwxrwx 1 root root 4 Jul 30  2010 /bin/sh -&amp;gt; bash&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Though bash behaves slightly different when called as /bin/sh rather than as /bin/bash (i.e. more like the traditional Bourne shell), it still is a Bash and not a Korn shell.&lt;BR /&gt;That might be the cause of the differences that you observe.&lt;BR /&gt;&lt;BR /&gt;Maybe you could try to prepend to your command string in the crontab a "SHELL=/bin/ksh " &lt;BR /&gt;Or if it's a Vixi crontab rather place this assignment at the top of the crontab on a line of its own.&lt;BR /&gt;But this I guess will apply to *all* crontab entries in this respective crontab. So be cautious.&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Jun 2011 11:26:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798464#M59864</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2011-06-16T11:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798465#M59865</link>
      <description>&amp;gt;The shell that we use is KSH.&lt;BR /&gt;&lt;BR /&gt;Is your script executable and as Steven asks, does it have:&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;Then it shouldn't matter to cron.</description>
      <pubDate>Sat, 18 Jun 2011 22:46:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798465#M59865</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-06-18T22:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798466#M59866</link>
      <description>&lt;!--!*#--&gt;&amp;gt; [...] /bin/sh [...] on Linux is a symlink&lt;BR /&gt;&amp;gt; to /bin/bash.&lt;BR /&gt;&lt;BR /&gt;Interestingly, this may be less true now than&lt;BR /&gt;it has been.  On my Debian system, for&lt;BR /&gt;example:&lt;BR /&gt;&lt;BR /&gt;debi# ls -l /bin/sh&lt;BR /&gt;lrwxrwxrwx 1 root root 4 Mar  9 08:27 /bin/sh -&amp;gt; dash&lt;BR /&gt;&lt;BR /&gt;debi# man dash&lt;BR /&gt;[...]&lt;BR /&gt;DESCRIPTION&lt;BR /&gt;     dash is the standard command interpreter for the system. [...]&lt;BR /&gt;&lt;BR /&gt;debi# ls -lL /bin/bash /bin/dash&lt;BR /&gt;-rwxr-xr-x 1 root root 1943176 Apr 10  2010 /bin/bash&lt;BR /&gt;-rwxr-xr-x 1 root root  232224 Dec 14  2010 /bin/dash&lt;BR /&gt;&lt;BR /&gt;As you can see, "dash" is more compact than&lt;BR /&gt;"bash", making it a better choice where a&lt;BR /&gt;basic (stripped-down?) shell is desired (as&lt;BR /&gt;for non-interactive use).&lt;BR /&gt;&lt;BR /&gt;debi# uname -a&lt;BR /&gt;Linux debi 2.6.32-5-mckinley #1 SMP Wed Jan 12 06:05:21 UTC 2011 ia64 GNU/Linux&lt;BR /&gt;&lt;BR /&gt;debi# cat /etc/debian_version&lt;BR /&gt;6.0&lt;BR /&gt;&lt;BR /&gt;Everything's complicated.</description>
      <pubDate>Sun, 19 Jun 2011 00:24:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798466#M59866</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2011-06-19T00:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Schedule in Linux - issue with newline character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798467#M59867</link>
      <description>&amp;gt;Interestingly, this may be less true now than&lt;BR /&gt;&amp;gt;it has been.  On my Debian system, for&lt;BR /&gt;&amp;gt;example:&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;debi# ls -l /bin/sh&lt;BR /&gt;&amp;gt;lrwxrwxrwx 1 root root 4 Mar  9 08:27 /bin/sh -&amp;gt; dash&lt;BR /&gt;&lt;BR /&gt;Hi Steven,&lt;BR /&gt;that's interesting news to me. I even haven't heard of "dash" yet.&lt;BR /&gt;Is it debian-specific? Because it of course the "d" sort of implies this.&lt;BR /&gt;&lt;BR /&gt;Ah yes, it seems so&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://en.wikipedia.org/wiki/Debian_Almquist_shell" target="_blank"&gt;http://en.wikipedia.org/wiki/Debian_Almquist_shell&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 20 Jun 2011 06:06:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/cron-schedule-in-linux-issue-with-newline-character/m-p/4798467#M59867</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2011-06-20T06:06:09Z</dc:date>
    </item>
  </channel>
</rss>

