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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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.