freebsd load command

hello there,
im running this in linux server but i cant run it on freebsd.
can someone help me out.. thanks
if [ "$TYPE" = "load" ]; then
INDATA=`cat /proc/loadavg | cut -d ' ' -f2 | sed 's/\.//g' | sed 's/^0//g'`
OUTDATA=`cat /proc/loadavg | cut -d ' ' -f3 | sed 's/\.//g' | sed 's/^0//g'`

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What are the error messages you are getting when running the command? Has the variable $TYPE been set in the environment? Are the switches you provided for cat, vut, and sed the same as in linux?
XK8ERAuthor Commented:
linux command doesnt work on freebsd so i have to use sysctl vm.loadavg instead..

*********linux system**********
[(01:37 PM)][(root@dedicated)] [(~)] $ cat /proc/loadavg
2.73 2.51 2.24 3/195 16583
[(01:37 PM)][(root@dedicated)] [(~)] $ uptime
 13:37:31 up 4 days,  2:28,  1 user,  load average: 2.73, 2.51, 2.24
[(01:37 PM)][(root@dedicated)] [(~)] $ cat /proc/loadavg | cut -d ' ' -f2 | sed 's/\.//g' | sed 's/^0//g'
[(01:37 PM)][(root@dedicated)] [(~)] $ cat /proc/loadavg | cut -d ' ' -f3 | sed 's/\.//g' | sed 's/^0//g'

$ sysctl vm.loadavg
vm.loadavg: { 0.09 0.27 0.38 }

then doing this
$ sysctl vm.loadavg | cut -d ' ' -f3 | sed 's/\.//g' | sed 's/^0//g'

the 09 its supposed to be 009

$ sysctl vm.loadavg | cut -d ' ' -f2 | sed 's/\.//g' | sed 's/^0//g'

all im trying to do is show the same as linux
seems to me like the cut command is different in freebsd, no?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

the cut command may be different in FreeBSD but thats not the first problem.

you can mount the proc file system in FreeBSD it has been deprecated and not mounted by default.

mount proc, add it to your /etc/fstab so that it mounts at startup

and try your command again.

Now, as to the output of commands, freebsd does not have the same output as linux in most commands.

ifconfig is different....

it could be cut thats different but in this case, I dont think so.

I think sed is your culprit.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
i would say try cut -f4 instead of f2 on the second statement and i believe rance is correct regarding sed since it is not replacing/removing the proper characters
stop chaining all your commands together, strip them all off and add them back one at a time, study the output each time.

what did you get,  what did you think you were supposed to get,

where is it broke?

at the cut, the first sed, or the second sed, or is your original data input not what you think it is?
I posted this in your other thread, try

uptime |awk '{print $8 $9 $10}'

you could tr -d the comma, if you only need one of those (tried with openbsd but should be similar anywhere)
on freebsd you dont need the second sed, the first on that strips out the '.' seems to return the data you want.

Im not really sure why you thought you needed the second one.

My comment (22953955) had the needed hint for him to answer and then the next day when there was no comment I provided the final answer (22959823)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.