Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
|
10-22-2016, 01:14 AM
|
#1
|
LQ Newbie
Registered: Oct 2016
Posts: 4
Rep: 
|
Linux Shell script not working on SunOs 5.10
Hi All,
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
|
|
|
10-22-2016, 01:47 AM
|
#2
|
Senior Member
Registered: Dec 2015
Posts: 1,641
Rep: 
|
Quote:
Originally Posted by hiten11
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?
|
|
|
10-22-2016, 01:58 AM
|
#3
|
LQ Newbie
Registered: Oct 2016
Posts: 4
Original Poster
Rep: 
|
Hi Micheal,
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.
|
|
|
10-22-2016, 02:02 AM
|
#4
|
Senior Member
Registered: Dec 2015
Posts: 1,641
Rep: 
|
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 ??
|
|
|
10-22-2016, 02:49 AM
|
#5
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
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.
|
|
|
10-22-2016, 06:31 AM
|
#6
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,040
|
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.
|
|
1 members found this post helpful.
|
10-22-2016, 06:57 AM
|
#7
|
LQ Guru
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 6,345
|
Quote:
Originally Posted by grail
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.
|
|
|
10-22-2016, 07:37 AM
|
#8
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
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.
bash
Quote:
/bin/sh on Solaris is a POSIX complaint bourne shell. If you have written bash-centric scripts, replace #!/bin/sh with #!/bin/bash
|
or visa versa as the case maybe. says that web page
|
|
|
10-22-2016, 09:37 AM
|
#9
|
Senior Member
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
|
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.
Hope this helps some.
|
|
|
10-24-2016, 12:29 AM
|
#10
|
LQ Newbie
Registered: Oct 2016
Posts: 4
Original Poster
Rep: 
|
Hi All,
Sorry for delayed reply .
When i am executing below command in SunOS
set -A Partition ( df -k | nawk -F' ' '{print $1}' )
I am getting error "bash: syntax error near unexpected token `('"
So am unable to store output in an array but when i am executing command i am getting output as list of all available filesystem
Filesystem
/
/appuser
/bocmsdata
/ctmag
/customlog
/dev
/fin62
/fin7012
/fin7014
/igrsdata
/oem10g
/ora11204
/ora12c
/oracle7 etc.
So kindly help me to get each of the above values in an array
|
|
|
10-24-2016, 01:03 AM
|
#11
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
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. $( ... )
Code:
partition=( $( df -k | nawk -F' ' '{print $1}' ) )
echo ${partition[*]}
|
|
|
10-24-2016, 02:01 AM
|
#12
|
LQ Newbie
Registered: Oct 2016
Posts: 4
Original Poster
Rep: 
|
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
Kindly find attached the snap
|
|
|
10-24-2016, 02:07 AM
|
#13
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,650
|
do not use ( ):
Code:
partition="$( df -k | nawk -F' ' '{print $1}' )"
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
|
|
|
10-24-2016, 05:29 AM
|
#14
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,040
|
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).
What is the output for the following:
Code:
df -k
df -k | nawk '{print $1}'
df -k | nawk -F' ' '{print $1}'
Obviously if there are issues with any of the above, then we can see about putting it in an array.
I would mention that the nawk command being used does not match any of the previous awk examples.
|
|
|
10-24-2016, 07:52 AM
|
#15
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
yeah I think everybody pretty much covered it, it is your syntax
Quote:
set -A Partition="$( df -k | nawk -F' ' '{print $1}' )"
|
now if that does not work then it is you  again????
in my terminal
Code:
userx@SlackDaddy & ~ >> $Partition="$( df -k | nawk -F' ' '{print $1}' )"
bash: nawk: command not found
(changed it to awk instead)
userx@SlackDaddy & ~ >> $Partition="$( df -k | awk -F' ' '{print $1}' )"
userx@SlackDaddy & ~ >> $echo $Partition
Filesystem /dev/root devtmpfs tmpfs tmpfs cgroup_root /dev/sdb4 /dev/sda3 /dev/sdb1 cgmfs
|
|
|
All times are GMT -5. The time now is 01:35 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|