Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
> Shell Script Troubles, Unsure how to do something
DemonWav
post Jan 3 2012, 11:13 PM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 1
Joined: 3-January 12
Member No.: 15,804



First off I want to start off saying that I am working on this script for an Android phone, so the commands are generally limited to busybox. If busybox can't do it, then neither can I. This is the entire script I am working on:
CODE
#!/sbin/sh

if [ -e /dev/block/mtdblock0 ]; then
    if [ -d /data ]; then
        /tmp/busybox mount -t ext4 /dev/block/mmcblk0p2 /data
    else
        /tmp/busybox mkdir mkdir /data
        /tmp/busybox mount -t ext4 /dev/block/mmcblk0p2 /data
    fi
    
    if [ -h /data/data/ ]; then
        /tmp/busybox touch /tmp/nofix
    else
        if [ -d /datadata ]; then
            /tmp/busybox mount -t yaffs2 /dev/block/mtdblock6 /datadata
        else
            /tmp/busybox mkdir /datadata
            /tmp/busybox mount -t yaffs2 /dev/block/mtdblock6 /datadata
        fi
        /tmp/busybox rm -rf /datadata/*
        FREE_SPACE=$(/tmp/busybox df -h | /tmp/busybox awk '$1 == "/dev/block/mtdblock6" {print $3}'); USED_SPACE=$(/tmp/busybox du -sh /data/data/ | /tmp/busybox awk '{print $1}')
        NEW_TERM=$(echo $FREE_SPACE $USED_SPACE | /tmp/busybox awk '{print $1 $2}')
        FREE_SPACE=$(echo $NEW_TERM | /tmp/busybox awk '{print $1}'); USED_SPACE=$(echo $NEW_TERM | /tmp/busybox awk '{print $2}')
        if [ $FREE_SPACE -gt $USED_SPACE ]; then
            /tmp/busybox touch /tmp/revert_pass
        else
            /tmp/busybox touch /tmp/revert_fail
        fi
    fi
else
    exit 1
fi


All goes well and good, until I get to line 22:
CODE
NEW_TERM=$(echo $FREE_SPACE $USED_SPACE | /tmp/busybox awk '{print $1 $2}')

Basically my problem is I need two integers to do the test in line 24:
CODE
if [ $FREE_SPACE -gt $USED_SPACE ]; then
and the output from the command on line 21:
CODE
FREE_SPACE=$(/tmp/busybox df -h | /tmp/busybox awk '$1 == "/dev/block/mtdblock6" {print $3}'); USED_SPACE=$(/tmp/busybox du -sh /data/data/ | /tmp/busybox awk '{print $1}')

is something like 132.5M for FREE_SPACE and 129.7M for USED_SPACE (I basically just made up those numbers, but they are numbers like that, 3 digits before the decimal, a digit after the decimal, and an M). What I am attempting to do with line 22 is try to maybe do 3 backspaces, if you will, on each of the two results. so 132.5M becomes 132 and 129.7M becomes 129. I don't need to know the decimal, it is really unimportant for my purposes. If I can accomplish that then I will be set for the rest of the script, but I really have no idea how to do that (or if its possible at all).
Go to the top of the page
 
+Quote Post

Posts in this topic
- DemonWav   Shell Script Troubles   Jan 3 2012, 11:13 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 22nd October 2017 - 11:32 PM