LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   disk quotas shell script (https://www.linuxquestions.org/questions/linux-newbie-8/disk-quotas-shell-script-929710/)

kalyanilinux 02-16-2012 09:04 AM

disk quotas shell script
 
Hello.. I wrote the following shell script to run disk quotas for assigning limits to users. I need to know the partition which the user has created and mount it. So i copied the partitions (which will be displayed after running fdisk -l) and separted the last line from it and cut the required partition name from it. Then this should be passed to the next line (using mount). Here I am facing the problem.. It is returning the error "device not found", that means the variable "$part" is not giving the partition name..

The following is my code:
Code:

VSIZE=100m;

fdisk /dev/sda >/dev/null 2>&1 <<EOF
n
p
3

+${VSIZE}M
w
EOF

partprobe /dev/sda

fdisk -l > file1

awk 'NF{s=$0}END{print s}' file1 > file2

part=(`cut -c "1 2 3 4 5 6 7 8 9 10" file2`)

mkfs.ext3 $part

mkdir /var/likes

mount $part /var/likes

chmod 777 /var/likes

quotacheck -cugv /var/likes

quotaon $part

setquota -u kal 2 3 4 5 -a $part


cbtshare 02-16-2012 02:39 PM

I'd advise you to put a
Quote:

echo "$part"
line in the script to see what it is actually returning.The you can fix from there.

kalyanilinux 02-16-2012 10:35 PM

Thanks for ur reply.I tried it,it is printing required value ( partition name) itself.But its not working in mount statement

cbtshare 02-16-2012 10:51 PM

I mean echo $part to see what is actually being printed after the
Quote:

part=(`cut -c "1 2 3 4 5 6 7 8 9 10" file2`)

This command doesnt seem to be working....I thing it should be
Quote:

cat file2 | cut
depending on what you wanna do..

chrism01 02-16-2012 10:54 PM

Try
Code:

set -xv
as the first line :)

kalyanilinux 02-16-2012 11:09 PM

@cbtshare
even this
Quote:

cat file2 | cut
is also not working fine :(

kalyanilinux 02-16-2012 11:13 PM

@Chris
what is meant by
Quote:

set -xv

chrism01 02-16-2012 11:23 PM

Try it & see ;)

Basically its a form of debugging; it shows you the before and after version (inc results) of parsing each line.
A key tool for fixing shell scripts.

http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

kalyanilinux 02-17-2012 12:04 AM

@chris
Thank you.. Ya it's debugging.. but what is the solution to solve the problem in code??


All times are GMT -5. The time now is 08:43 PM.