- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: cron environment issue
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 02:23 AM
тАО02-13-2007 02:23 AM
The idea is to separate the char from the numeric.
#!/usr/bin/ksh
ii=123g
num=`echo $ii|tr -d [a-z]`
char=`echo $ii|tr -d [0-9.]`
echo "string is $ii"
echo "num is $num"
echo "char is $char"
The output is as follows when running as root from cron.
string is 123g
num is 123g <<-- should just be 123
char is g
Any help/ideas would be appreciated.
Solved! Go to Solution.
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 02:33 AM
тАО02-13-2007 02:33 AM
Re: cron environment issue
I'd be interested in your 'locale' settings when you run along with the 'whence' output of 'echo' and 'tr'. Add this to your script:
# locale
# whence echo
# whence tr
...and compare under the conditions you describe.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 02:43 AM
тАО02-13-2007 02:43 AM
Re: cron environment issue
from "man tar"
c1-c2 Stands for the range of collating elements c1 through c2, inclusive, as defined by the current setting of the LC_COLLATE locale category.
[:class:] Stands for all the characters belonging to the defined character class, as defined by the current setting of LC_CTYPE locale category. The following character class names will be accepted when specified in string1: alnum, alpha, blank, cntrl. digit, graph, lower, print, punct, space, upper, or xdigit, Character classes are expanded in collation order.
Probably down to LC_COLLATE and/or LC_CTYPE.
Have you tried:
num=`echo $ii|tr -d [:alpha:]`
char=`echo $ii|tr -d [:digit:]`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 02:44 AM
тАО02-13-2007 02:44 AM
Re: cron environment issue
echo
/usr/bin/tr
shell is /usr/bin/sh
string is 123g
num is 123g
char is g
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 02:50 AM
тАО02-13-2007 02:50 AM
Re: cron environment issue
LANG=
LC_CTYPE="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_MESSAGES="C"
LC_ALL=
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 03:16 AM
тАО02-13-2007 03:16 AM
Re: cron environment issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 03:23 AM
тАО02-13-2007 03:23 AM
Re: cron environment issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 03:26 AM
тАО02-13-2007 03:26 AM
Re: cron environment issue
echo
/usr/bin/tr
shell is /usr/bin/sh
string is 123g
num is 123g
char is g
Notice that stripping off the numeric works. The trouble is with the non-numeric.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 03:42 AM
тАО02-13-2007 03:42 AM
SolutionI really recommend to have the char-class quoted:
NOT
num=`echo $ii|tr -d [a-z]`
but
num=$(echo $ii|tr -d '[a-z]')
If you have one-letter file(s) a x c in your current directory, the filename matching will blow the 'tr'.
mfG Peter
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 03:49 AM
тАО02-13-2007 03:49 AM
Re: cron environment issue
ii=123g
num=$(echo ${ii} | tr -d "[a-z]")
echo "num is ${num}"