• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to convert float to integer number

May 23, 2013 by Sharad Chhetri Leave a Comment

How to convert float to integer number

In this tutorial we will learn how to convert float to integer number.
This tutorial is helpful in bash or shell scripting.

For eg. the float value number is 204.47584 and you would like to show only number in integer form means upto 204. So for this use the given below steps.

[root@server ~]# FLOAT=204.47584
[root@server ~]# INT=${FLOAT/.*}
[root@server ~]# echo $INT
204
[root@server ~]#

Now I can use this logic in bash script.
In given below example, I am monitoring Java command when consumes more than 90% it will send me email to my email-id.

This is just for an example,you can make it better with putting some more logic.

#!/bin/bash
## convert float to integer number

xyz=`ps -eo pcpu,user,comm,pid | sort -k 1 -r | head -2|grep java`
FLOAT=`ps -eo pcpu,user,comm | sort -k 1 -r | head -2|grep java|awk ‘{print $1}’`
INT=${FLOAT/.*}

if [ $INT -gt 90 ]
then
echo “CPU usage by mysql server is $INT, Report: $xyz”|mail -s “java cpu usage in percentage” joe@example.com
else
exit
fi

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. subtract integer written in columns from 2 different files
  2. Convert hyphen to underscore in between all filenames shell script
  3. How to convert rpm file into deb file
  4. Convert video file into gif file through command line in linux
  5. Convert new line to space by using sed command
  6. convert space into new line using sed command
  7. Convert website page to pdf and image
  8. tr command to convert lines to space , tab and vertical tab
  9. send email after mysql backup through bash script in simple way
  10. Install and optimize the png file by using optipng

Filed Under: Linux, Tips And Tricks Tagged With: bash script

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Linux Commands

grep command to remove commented lines

Linux / Unix : whoami command use and advantage

Eject Command: Eject DVD-ROM Or CD-ROM In Linux

vi : Edit file without opening it

What is Linux/Unix Internal And External Command

tr command to convert lines to space , tab and vertical tab

How to list users above or below particular user id

Explore 70+ Articles On Linux Commands

Always Useful Tips And Tricks

How to change hostname in Ubuntu 12.04 and 12.10 without system restart

error command ‘gcc’ failed with exit status 1 in Ubuntu

How to empty Trash through command line in Ubuntu

AttributeError: ‘WSGIRequest’ object has no attribute ‘session’ Django python web framework

Run the script using nohup without hitting enter key two times

How to install pam_mysql in CentOS or Red Hat

df command not showing correct free space in linux

Explore 90+ Article On "Linux Tips And Tricks"

You Might Like These Articles!

Linux basic command

Linux Basic Commands For Every Beginner

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission but Schools and Colleges can do in their Private Network
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy