i have to do this script
./myscript.sh /a/dir1/vol/vol0
4%
i need to create a script then run it while typing the directory of mounted volume in the same line. then it should show only the percent of usage
i have to do this script
./myscript.sh /a/dir1/vol/vol0
4%
i need to create a script then run it while typing the directory of mounted volume in the same line. then it should show only the percent of usage
If I understand correctly, you want to pass an argument (the mounted volume) to your script. Here is a very simple example (dfScript.sh
) of how I would do that:
#!/bin/bash
# Get the volume from command line
volume="$1"
df -h "$volume" | egrep -o '[0-9]+%'
exit 0
Calling this would look something like:
./dfScript.sh /home/
12%
$1
is the first argument passed to the script, in this case I used my /home
directory as an example, but you can of course provide the path to any volume.
Also, you don't really need to assign $1
to a variable to use it, I just did so above for clarity.
You can read more on passing arguments to bash here.
what i did was
df -h | grep vol0 | awk '{print $5}' 16%
but the problem is I can't turn it to script then provide the directory of mounted volume.
sorry i am really a beginner.
– kukiaz Oct 16 '16 at 09:34Yes, and actually I am really confused if it is really possible to execute the script like
Line 1: ./myscript.sh /a/dir1/vol/vol0 Lilne 2: 4%
line 1 will run myscript.sh and will use /a/dir1/vol/vol0 as input ( input can be changed depending on target volume) line 2 will just show the current use%
– kukiaz Oct 16 '16 at 09:49