- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Cannot handle names with spaces/unusual charac...
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
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
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
11-14-2011 12:58 AM
11-14-2011 12:58 AM
Cannot handle names with spaces/unusual characters in script
Hello,
I am writing a small script to check filesystem usage by doing remsh to remote hosts. The script does the following:
- Connect remote host an do:
remsh ${SYSTEM} "du -sk * | sort -k1n > /tmp/fsusage"
- List the contents of the biggest directories in remote system:
remsh ${SYSTEM} "tail -5 /tmp/fsusage |awk '{print\$2}' |xargs -n1 -i ls -ldF $FIL/{}"
It works well except when it finds directories like these:
======> Result of "du -sk *"
595570 DIR1
658118 XXXX YYY
1906674 DIR2
5752242 Mª Rose
7672140 DIR3
======> List:
/XXXX not found
drwxr-xr-x 8 smbnull smbnull 30720 Nov 13 02:00 /DIR1/
/Mª not found
drwxr-xr-x 2 smbnull smbnull 96 Nov 11 10:26 /DIR2/
drwxr-xr-x 2 smbnull smbnull 2048 Nov 14 07:41 /DIR3/
How can I handle directory names made up of two o more words? I think it could be done by putting in the awk statement "from field two onwards", but I don't know how to write it...
Best Regards,
- Tags:
- awk
- evil spaces
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2011 12:29 PM - edited 11-14-2011 01:07 PM
11-14-2011 12:29 PM - edited 11-14-2011 01:07 PM
Re: Cannot handle names with spaces/unusual characters in script
>How can I handle directory names made up of two or more words? I think it could be done by putting in the awk statement "from field two onwards"
You could check NF and see if more than 2 fields:
dir = $2
if (NF > 2)
dir = $2 " " $3
But this would fail if more than 1 space.
You could parse $0 and take everything after the first group of spaces.
But then your next ls(1) pipeline may also fail. Better to not have evil spaces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2011 12:59 PM
11-14-2011 12:59 PM
Re: Cannot handle names with spaces/unusual characters in script
> [...] "from field two onwards" [...]
Not the best plan, I claim. You don't want fields, you want
directory names. A name like "a b" is one thing, but what about
"a b"? There are things in "awk" like, say, substr() which might be
useful, but trying to extract a directory name from the "du" output
sounds to me like a direct path to problems.
I haven't tried anything serious, but I'd probably start with some
kind of "find" command to get the actual names. For directories, say:
find . -type d
dyi # ls -l
total 0
drwxr-xr-x 2 root sys 96 Nov 14 02:18 leading space
drwxr-xr-x 2 root sys 96 Feb 11 2010 itrc
drwxr-xr-x 2 root sys 96 Nov 14 02:36 middle spaces
drwxr-xr-x 2 root sys 96 Nov 14 02:18 trailing space
(I'd bet that there's a smarter way to do the following:)
dyi # find . -type d -exec echo {} \; | sed -e 's/^\(.*\)$/>\1</'
>.<
>./itrc<
>./ leading space<
>./trailing space <
>./middle spaces<
In any case, then, I might feed those names from "find" into separate
"du" commands. For example:
dyi # find . -type d -exec du -ks {} \;
104 .
96 ./itrc
0 ./ leading space
0 ./trailing space
0 ./middle spaces
Depending on exactly what you want, getting everything onto one line
may be difficult. I'd expect to write a script, and copy that script
around to all the remote systems.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2011 01:41 AM
11-22-2011 01:41 AM
Re: Cannot handle names with spaces/unusual characters in script
Hi,
Thank you all for your help. Eventually I managed to put into double quotes the names with spaces.
Regards,
P.s. ¿How can assign points?
- Tags:
- quoting