Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
I have made a script that will output filesystem used space % using df -h command.Kindly find the script below
Code:
#!/bin/bash
Partition=($(df -h |grep ^/ | awk '{print$1}'))
Used=($(df -Pk |grep ^/ |awk '{print$5}' | sed "s/[^0-9]//g"))
for ((i=0; i<${#Partition[*]}; i++));
do
echo "File System ${Partition[i]}used space is ${Used[i]}"
done
But the same is not working on "SunOS 5.10 Generic_150400-29 sun4v sparc SUNW,T5440"
Can Anyone help me to achieve similar output in Solaris 5.10 too
But the same is not working on "SunOS 5.10 Generic_150400-29 sun4v sparc SUNW,T5440"
Can Anyone help me to achieve similar output in Solaris 5.10 too
I see, that you are pragmatic, but as some of the people on LQ are geniuses without even knowing your Solaris-system, it could help to give us an error-message or other detail which may hint at the origin of your observed incompatibility.
Would it not be great to just make your own script work, instead of being blessed with a free, working Solaris-specific solution?
Sorry for that , i want to make a script that will echo used space across all partitions that are visible in df -k command.In the first line
Partition=($(df -h |grep ^/ | awk '{print$1}'))
I am parsing all the available filesystem in "Partition" array but am not able to achieve the same in SunOs, same code is working well in Linux.
For rest of the lines that i have posted , i myself have found out a workaround.It would be great if you could help me out in parsing available Filesystem in an array.
Okay, this might become awkward, as I do not have a Solaris-system at my disposition.
My question is this: When you run your script on Solaris, WHAT HAPPENS ??
In addition to the exact error message, there are some things to check. One is be sure that "df -h" on both systems create similar output. Run them outside of the script and compare them manually. Another is removing the redundant "grep", since "awk" can do some pattern matching:
Code:
Partition=($(df -h | awk '/^\// {print$1}'))
Also, why do you have the extra parenthesis? They change what $Partition gets filled with.
Having worked with Solaris only a little bit, my questions would be:
1. Does it have bash? If so, what version? (none that I have worked on did)
2. Does it have awk? If so, what version?
3. Does it have df? If so, are all the switches applicable?
You can probably see where this is going. on top of what the others have already asked about error messages, when you are on a completely different type of system you need to provide a lot more information as
most of us have either not worked with your system type or do not currently have access to one so we cannot replicate your issues.
Having worked with Solaris only a little bit, my questions would be:
1. Does it have bash? If so, what version? (none that I have worked on did)
2. Does it have awk? If so, what version?
3. Does it have df? If so, are all the switches applicable?
You can probably see where this is going. on top of what the others have already asked about error messages, when you are on a completely different type of system you need to provide a lot more information as
most of us have either not worked with your system type or do not currently have access to one so we cannot replicate your issues.
Good advice! And, if I may add, entire books have been written on portability. You appear to have read none of them, and seeking some for some reading might be wise.
You are using multiple tools for this and on an operating system where NONE of them are sure to be GNU standard! Generally, a portable script will use /bin/sh and only relatively posix standard shell features. Called utilities will use only the most standard features, and as few of those as can be managed. Even then, conditional execution based upon detected differences may be required.
I like what you are doing, not for utility but as a learning exercise. This is a perfect setup for a lesson in portability.Please let us know the results of your research and testing.
compatibility is the issue here -- yes that is it have you tried looking up how to write a script SunOS to find the differences between the two?
Apples MAC too is a UNIX based system but I bet it too has its quirks when it comes to running bash commands, even Solaris too would fall into this pit.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
There are usually two versions of awk on Sun systems, oawk and nawk (old and new). oawk is traditional AWK and does not work the same as nawk, which is the current version being maintained by Brian Kernighan at his Princeton web site. /usr/bin/awk is a symbolic link to either oawk or nawk, typically oawk because some utilities have not been updated to use nawk. Perhaps you can check and see if there are different results (modify awk to oawk then the to nawk)?
If you're interested in nawk, which, in my opinion, is a better alternative to gawk on Linux systems, you can download the source from http://www.cs.princeton.edu/~bwk/ and compile it on your Linux system (it compiles to an a.out, you copy that to, say, /usr/local/bin/nawk.
I can't find my old OpenSolaris discs and Oracle's download function is *%$#^&* broken, perhaps on purpose. I never found them worth the money when I have encountered them in the past, anyway. And given their priorities, acquiring Solaris is only trouble. I notice that most of the OpenSolaris derivatives available outside of Oracle have mostly defaults of using the GNU userland. But I digress.
Presumably, if you are using bash, you should use the syntax for GNU Bash instead of for one of the Solaris shells. You'll need to make use of command substitution though. $( ... )
Hi I tried the above command but the execution of this command is not getting completed successfully and i have to explicitly press ctrl^c to kill the command
and as it was already mentioned please post not only the command you tried but the result as it was displayed. Exactly! Saying "not getting completed successfully" will not help anyone to give you any help
Well the OP did want an array so I see why the extra () are needed. Maybe we could take a step back now that we have (sort of) identified answers to some questions (although indirectly).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.