Saturday, January 24, 2015

Building Main Menu and Accessing Mount Points

The main menu was written using a case style set of arguments for what the user would input, but I had to ask online how to have it default to an option on its own after 10 seconds. It turns out that the read command to accept user input has that option in-built, so it was very simple. It's not 100% as nice as I'd like it, so I may someday take the time to rewrite it to use a ncurses "dialog" box instead, but for now it functions just fine. The actual graphics of the menu became a problem later on, but that will be for another post.

One desired feature of the program was that it would have the options to either assume the target hard drive would be in a certain place and attempt the changes or to find all accessible drives and mount them and make changes to all of them. Once again, searching the internet and asking for help provided the commands I needed. It turns out that using 'awk' to choose out a pattern something like /dev/sd[a-z][0-9]/ and then { print $6 } was the way to select only the 6th column of any line containing the pattern.

Integrating this into a while loop was also something that I needed help with since I didn't know about <( functionality in bash scripts. So what I had at the end was something like
while read mPoint
do
#stuff
done < <(df -P | awk '/Sda[a-z][0-9]/ { print $6 })
Which would take the output of all the commands in parenthesis (find all mounted partitions, then choose out the patterns and print only column 6) and load the "answer" into the variablemPoint. Then I could do things with $mPoint inside the while loop. This technique would be used again later to mount all drives, but I may still change that.

No comments:

Post a Comment