LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-28-2013, 07:38 PM   #16
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444

my bad

Code:
RootFSDev=$( lsblk -o KNAME,type,MOUNTPOINT | awk 'if ($3 == "/"){sub(/[1-9]+,"");print $1}' )
should be
Code:
RootFSDev=$( lsblk -o KNAME,type,MOUNTPOINT | awk '$3 == "/"{sub(/[1-9]+/,"");print $1}' )
 
Old 10-28-2013, 07:49 PM   #17
powerplyer
LQ Newbie
 
Registered: Mar 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
Excellent it worked, now where do I change your code to test out the output of like a fdisk -l command?

BTW if I wanted to get rid of the "Format another device" and let the script continue running after the command is completed.

Code:
Output:
[root@ Desktop]# ./test.sh
1) Quit
2) /dev/sdb
3) /dev/sdb1
4) /dev/sdb2
5) /dev/sda
Which device would you like to format?: 5
/dev/sda
1) Yes
2) No
Format another device?: 2
[root@ Desktop]#
Thanks again for your help.

Last edited by powerplyer; 10-28-2013 at 08:00 PM. Reason: Sorry bad english
 
Old 10-28-2013, 08:34 PM   #18
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
instead of exit, use break

you will also need a second break, beciase my code is sloppy

here , I have 'complicated' it, so you get more info

Code:
#!/bin/bash
Options=("Quit") # create array
RootFSDev=$( lsblk -o KNAME,type,MOUNTPOINT | awk '$3 == "/boot"{sub(/[1-9]+/,"");print $1}' )
while read -d @ Devices;do
    Options+=("${Devices}")
done <<< $(lsblk -o KNAME,type,MOUNTPOINT | awk '/disk/||/part/{if ($1 != "'$RootFSDev'" && $3 != "/" )print "/dev/"$1" "$3"@"}')
# print field 3 (mountpoint) and end line with @
# in the while read -d @ is the delimiter
# add each element to the array with  Options+=("${Devices}")
# elements will be in the form "/dev/sdX " or , if mounted "/dev/sdX /mountpoint"

ShredSelect () {
PS3='Which device would you like to format?: '
select Disk in "${Options[@]}";do
   case $Disk in
     Quit)
           break
        ;;
       '')
           echo "Please select option 1 to ${#Options[@]}: "  
        ;;
        *)
           
           ShredDevices+=(${Disk% *})

           # ${Disk% *}
           # http://www.tldp.org/LDP/abs/html/refcards.html#AEN22664
           # ${string%substring}        Strip shortest match of $substring from back of $string
           # we need to remove the trailing <space>mountpoint
           PS3="Format another device?: "
           select YN in Yes No;do
               case $YN in
                 Yes)
                      ShredSelect
                      return
                   ;;
                  No)
                      break
                   ;;
               esac
           done
           break
        ;;
   esac
done

# best to call a function, passing it ShredDevices array
Fdisk_func ${ShredDevices[@]}


return
}
Fdisk_func () {
for i in $@;do
    fdisk -l $@
done
return
}
ShredSelect

adding to the ShredDevices array, and processing 'all at once' is optional

instead of ShredDevices+=(${Disk% *})

Code:
Fdisk_func ${Disk% *}
and remove Fdisk_func ${ShredDevices[@]}

Edit:

I will let you do some code to present the final 'shredlist', with ability to edit ( remove, add more etc )
and final confirm and stuff

Last edited by Firerat; 10-28-2013 at 08:36 PM.
 
Old 10-28-2013, 09:38 PM   #19
powerplyer
LQ Newbie
 
Registered: Mar 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
excellent thank you very much...

wish me luck..

I will keep the team posted and mark it as solved once I get it right.

Last edited by powerplyer; 10-28-2013 at 09:39 PM. Reason: I have to learn to proof read
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Defining variables/arrays in csh from stdn/user input eamesj Programming 5 12-31-2012 12:20 AM
[SOLVED] Perform an action on a list/array of variables from user input in bash eamesj Programming 1 12-30-2012 11:22 PM
Selecting preset variables by user input in a bash script Lateralus138 Programming 12 09-27-2012 03:33 AM
using read and setting variables from user input string tekgek Programming 1 11-27-2008 02:10 AM
changing variables using user-input Kai' Linux - General 3 04-29-2008 07:04 PM


All times are GMT -5. The time now is 01:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration