freebsd load command

Posted on 2008-11-13
Last Modified: 2012-06-27
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

Question by:XK8ER
    LVL 3

    Expert Comment

    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?
    LVL 1

    Author Comment

    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
    LVL 3

    Expert Comment

    seems to me like the cut command is different in freebsd, no?
    LVL 8

    Accepted Solution

    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.


    LVL 3

    Expert Comment

    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
    LVL 8

    Expert Comment

    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?
    LVL 3

    Expert Comment

    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)
    LVL 8

    Expert Comment

    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.

    LVL 8

    Expert Comment

    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)

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
    Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now