vortexbox.org

06 Nov 08 Forum

You must be logged in to post Login Register

Search Forums:


 






How-To: Display $storageinfo for 2nd Harddrive

UserPost

5:31 pm
January 16, 2010


stevo

Member

posts 19

Hi,


1ST, thank you so much for Vortex Box. You sucessfully converted my worthless old computer into a priceless entertainment icon. :)


After a sucessful audio installation, I decided to add a 2nd large harddrive to the Vortexbox to serve only videos…

everything is installed, partitioned, formatted, etc.

I mounted the new 250g partition to /storage/movies

Everything works fine, I can add my video files directly or via the network and I can access them in the /storage/movies directory.


My question is: How do I get a second $storageinfo  line to display in index.php? for the new drive I added.

The results of  "df -h –total /storage/movies | grep total"  correctly displays size, used, avail, percent for the new drive…but how do I add it permanently into the index.php file. Im a newb at programming and dont understand what $smarty is doing.


What I tried (highlighted below orange/red) did not work. Could you please show me what I need to add/change to correctly make this display my large hardrive storageinfo on the index page?

———————————————————

$smarty = new Smarty;
$smarty->caching = 0;

$smarty->compile_check = true;
$smarty->debugging = false;

require '/var/www/html/libs/vortexbox.php';

$lines = file($smbfile);
$smblines = array();
foreach ($lines as $line_num=>$line) {
  if ( ! preg_match("/#.*/", $line) ) {
  # Contains non-whitespace?
  if ( preg_match("/S/", $line) ) {
  list( $key, $value ) = explode( "=", trim( $line ), 2);
  $smblines[trim($key)] = trim($value);
  }
   }
}
$smarty->assign('SYSNAME', strtolower($smblines['netbios name']));

$storageinfo2 = explode(" ",StripExtraSpace(exec("df -h –total /storage/movies | grep total")));
$smarty->assign('STORAGESIZE', $storageinfo[5]);
$smarty->assign('STORAGEUSED', $storageinfo[6]);
$smarty->assign('STORAGEAVAI2', $storageinfo[7]);
$smarty->assign('STORAGEPERCENT', $storageinfo[8]);

$storageinfo = explode(" ",StripExtraSpace(exec("df -h –total /storage | grep total")));
$smarty->assign('STORAGESIZE', $storageinfo[1]);
$smarty->assign('STORAGEUSED', $storageinfo[2]);
$smarty->assign('STORAGEAVAIL', $storageinfo[3]);
$smarty->assign('STORAGEPERCENT', $storageinfo[4]);

$smarty->assign('IPADDRESS', $ipaddress);
$smarty->assign('MACADDRESS', $macaddress);
$smarty->assign('VORTEXBOXVERSION', $VortexBoxVersion);

$smarty->display('index.tpl');

———————————————————-


Thank you =))

5:50 pm
January 16, 2010


Andrew

Admin

posts 1624

Go into templates and edit the template for index you can add display your new variables. Keep in mind if you do an upgrade your code may be over written so back up your changes.

6:52 pm
January 16, 2010


stevo

Member

posts 19

SWEET!!!

Thank you so much for a fast reply  Laugh



7:31 pm
January 18, 2010


stevo

Member

posts 19

That works so well, and was easy enough to implement…that I had to re-partion the new harddrive (again) so I can have a seperate place for pictures too, and then monitor all 3 storage areas from the webpage. Smile


In case some one else wants to monitor disk consumption on their extra harddrive/partitions, I'll put the necessary details here.

This assumes you have already installed the hardware, and decided on a mounting point for a seperate partition than the logical volume originally created with the installation…like a new partition on a 2nd drive.

 

1st you will need to login to ur vortex box command line as root, with the password you provided at the install.

 

__________________________________________________

NOTE: BEFORE EDITING ANY FILE, MAKE A BACKUP COPY 1ST.

                          cp index.php index.php.bak

__________________________________________________

 

Then navigate to /var/www/html  :   cd /var/www/html 

 

then use command:   nano index.php

 

Alternatively, you could just use command: nano /var/www/html/index.php

, but I prefer to navigate to where Im working so I will give the rest of the directions as such.

Go to the following section of the index.php file:

 

$smarty->assign('SYSNAME', strtolower($smblines['netbios name']));

$storageinfo3 = explode(" ",StripExtraSpace(exec("df -h –total /storage/pictures | grep total")));
$smarty->assign('STORAGESIZE3', $storageinfo3[1]);
$smarty->assign('STORAGEUSED3', $storageinfo3[2]);
$smarty->assign('STORAGEAVAIL3', $storageinfo3[3]);
$smarty->assign('STORAGEPERCENT3', $storageinfo3[4]);

$storageinfo2 = explode(" ",StripExtraSpace(exec("df -h –total /storage/movies | grep total")));
$smarty->assign('STORAGESIZE2', $storageinfo2[1]);
$smarty->assign('STORAGEUSED2', $storageinfo2[2]);
$smarty->assign('STORAGEAVAIL2', $storageinfo2[3]);
$smarty->assign('STORAGEPERCENT2', $storageinfo2[4]);

$storageinfo = explode(" ",StripExtraSpace(exec("df -h –total /storage | grep total")));
$smarty->assign('STORAGESIZE', $storageinfo[1]);
$smarty->assign('STORAGEUSED', $storageinfo[2]);
$smarty->assign('STORAGEAVAIL', $storageinfo[3]);
$smarty->assign('STORAGEPERCENT', $storageinfo[4]);

 

I added whats marked in red or orange, you can copy and paste the original code(in black) to make it easier on yourself. Use these directions to copy-paste in nano.  The parts marked in blue are what I added or changed from the original code. You could use any name for your variables, I just tried to keep it intuitive.

When you're finished editing, CTRL-X to exit and make sure you save your changes to the file.

 

1 more file to edit…

 

Now go to /var/www/html/templates :  cd /var/www/html/templates

or if you're still in the same directory, just:  cd templates

now edit the  index.tpl  file :  nano index.tpl

Go to the following section of the index.tpl file:

 

 <table>
 <tr><th>Filesystem</th>
  <th>Size</th>
  <th>Used</th>
  <th>Available</th>
  <th>Use%</th>
 </tr>
 <tr><td>/storage/music</td>
  <td>{$STORAGESIZE}</td>
  <td>{$STORAGEUSED}</td>
  <td>{$STORAGEAVAIL}</td>
  <td>{$STORAGEPERCENT}</td>
 </tr>
 <tr><td>/storage/movies</td>
  <td>{$STORAGESIZE2}</td>
  <td>{$STORAGEUSED2}</td>
  <td>{$STORAGEAVAIL2}</td>
  <td>{$STORAGEPERCENT2}</td>
 </tr>

 </tr>
 <tr><td>/storage/pictures</td>
  <td>{$STORAGESIZE3}</td>
  <td>{$STORAGEUSED3}</td>
  <td>{$STORAGEAVAIL3}</td>
  <td>{$STORAGEPERCENT3}</td>
 </tr>
 </table>

 

Once again, I added the red and orange sections(copy-paste). Note the corresponding changes(marked in blue) related to the variables we created in the index.php file.

When you're finished editing, CTRL-X to exit and make sure you save your changes to the file.

 

________________________________________________

FINAL NOTE: Make sure to make your new mount points pemanent in  /etc/fstab

________________________________________________

 

My additions to fstab looked something like this:

/dev/sdb1          /storage/pictures      xfs      defaults    1 2

/dev/sdb2          /storage/movies        xfs      defaults    1 2

 

Good luck, post here if I left something out or if you have any questions :)

 

 

!st

11:29 am
January 21, 2010


Patricia P

Bromley

Member

posts 34

Hi I have a PC with vortexbox v0.9 which amalgamates two hard drives, one usb one sata.

/ ext4 /dev/mapper/VolGroup-lv_root

I want to remove the usb drive as I dont need the extra space, and it uses power when on.

I need to adapt your script to "see" files on the usb drive and sata drive and to then put them all onto the sata drive.

Its easier for me to just format the drives, buying a new drive to copy them onto. But if you have another solution I'd be very interested.


11:32 am
January 21, 2010


Patricia P

Bromley

Member

posts 34

The post doesnt make sense because the formatting is off

the page.

Hi I have a PC with vortexbox v0.9 which amalgamates two

hard drives, one usb one sata.

/ ext4 /dev/mapper/VolGroup-lv_root

I want to remove the usb drive as I dont need the extra space,

and it uses power when on.

I need to adapt your script to "see" files on the usb drive and

sata drive and to then put them all onto the sata drive.

Its easier for me to just format the drives, buying a new drive

to copy them onto. But if you have another solution I'd be very interested.

5:05 pm
January 22, 2010


stevo

Member

posts 19

Hi Patricia,


I dont think the small changes I made to Andrew's web code will help you with your situation. This is simply meant to be an addition to Andrews code to include monitoring of additional harddrives other than the dedicated harddrive that Vortexbox is initially installed to.


Oh no, dont format your drives quite yet, especially the USB drive… if you already ripped a lot of music, a do-over would be a pain. So, Im guessing a little at your intentions here, but if you just want to move the files off of the usb drive, and onto the sata drive, then there is most likely an easy way to do it. And since you are using version .9 of vortexbox, this could be a good opportunity to upgrade to version 1 anyway.

( This will work as long as your usb drive is formatted with fat or fat32 )

The easiest way (Windows method) would be to access the vortexbox server across the network via any windows computer. (pls make sure the vortexbox server and the windows computer are in the same workgroup, and the USB drive is unplugged from the vortexbox server)

If you decided to upgrade to Vortexbox ver 1.0, then you are ready to start copying…if you are going to still use ver .9, you will need to 1st re-configure the VortexBox to store files on the sata drive at the default location and mounts. Afterwards you might want to test rip a cd and make sure everything works as expected.  Now, plug the usb drive into any windows box, and then drag-n-drop the files to the vortexbox server into the appropriate directory. For example, from a windows perspective the right place would be /files/music/flac , /files/music/mp3 , ect…

After you sucessfully move the files, it would be a good idea to go into the squeezbox server and rescan the music library, just to make sure its all accessable on the network.


Alternatively, if you feel comfortable at the commmand line…and if you upgraded to Ver 1, then you could just plug the USB drive into the new vortexbox and copy the files directly.

  • login to your vortexbox server
  • plug the usb drive in  – -(note the device assignment, example: sdc1 )
  • type – mkdir /mnt/usbdrive
  • type – mount /dev/sdc1 /mnt/usbdrive
  • type – cd /mnt/usbdrive
  • type – ls       – -(you should see your usb drive's folders)

I dont know the directory structure on your USB drive, so Im assuming default. adjust these commands to suit your specific layout.

  • type – cp -a storage/music/flac/* /storage/music/flac

If everything went ok, that should copy all your ripped flac music files and album art to the new vortexbox hardrive in the correct directory. If you have MP3 files too, the command will be similar:

  • type – cp -a storage/music/mp3/* /storage/music/mp3

Repeat that basic command for any other files you have stored on the usb drive, just change the copy to/from locations.


Once you have finished copying all files, it would be a good idea to go into the squeezbox server and rescan the music library.

7:37 pm
January 22, 2010


Patricia P

Bromley

Member

posts 34

Thanks for your comment, but its hard to interpret. There is a problem with

the formatting of your reply – that affected my post also. I had to manually

enter CR every few words. We need to get Andrew or webadmin to address

this. Or is this only affecting my browser?

7:41 pm
January 22, 2010


Patricia P

Bromley

Member

posts 34

Looks fine with IE – mozilla cuts away part of the right side of the post! Anyway I'll read it now. Embarassed

8:16 pm
January 22, 2010


Patricia P

Bromley

Member

posts 34

You guessed correctly – I do want to transfer all my music to the sole internal drive and change the drive location for music to that drive.

The usb drive was formatted when vortexbox 0.9 was installed and dont remember the options if any for formatting. I know that when I disconnect the usb drive and try to run the server it wont initialise as its missing part of the spanned drive (not sure if that's the right term, but the two drives are treated as one single drive.) I suppose that the iso of VB 1.0 will run and identify any drives connected.

I assumed that running the vortexbox 1.0 iso would format any drive attached to the pc without giving another option.

Is there a menu on installation allowing you to choose just to upgrade, and choose the drive location for music?

Sorry for such a palaver.

8:52 pm
January 22, 2010


stevo

Member

posts 19

Patricia P said:

I assumed that running the vortexbox 1.0 iso would format any drive attached to the pc without giving another option.

Is there a menu on installation allowing you to choose just to upgrade, and choose the drive location for music?


You can plug the usb drive into any windows computer, if you can access the files, then you can use the windows drag and drop method.


Andrew would be the one to ask about alternate installation possibilities.


If you want to upgrade to vortexbox 1.0, I would just leave the usb drive disconnected, so it will install itself normally…then plug the usb drive in and follow the command line procedure above to copy over your music.

8:46 pm
January 25, 2010


stevo

Member

posts 19

Andrew said:Go into templates and edit the template for index you can add display your new variables. Keep in mind if you do an upgrade your code may be over written so back up your changes.


 Thank you for that good advice :)


I upgraded and sure enough, everything was gone…but took only 2 minutes to restore.


8:55 am
July 14, 2010


stevo

Member

posts 19

Just a quick note to let you know this code works fine in Vortexbox 1.4, no conflicts, etc..

BUT,

The index.php file has been updated, so I didnt restore from back-ups this time, I just repeated the procedure above, and all is well.

BTW, Andrew, Vortexbox has been running flawlessly for 7 months now, thanks again for all your hard work here.


                 I LOVE MY VORTEXBOX

 

Can I get a t-shirt that says that?  =))

9:10 am
July 14, 2010


stevo

Member

posts 19

OOPS, Sorry, I just noticed a typo in the part about:

 edit the  index.tpl  file :  nano index.tpl

 <tr><td>/storage/movies</td>
  <td>{$STORAGESIZE2}</td>
  <td>{$STORAGEUSED2}</td>
  <td>{$STORAGEAVAIL2}</td>
  <td>{$STORAGEPERCENT2}</td>
 </tr>
 </tr>   <————— oops, remove this typo
 <tr><td>/storage/pictures</td>
  <td>{$STORAGESIZE3}</td>
  <td>{$STORAGEUSED3}</td>
  <td>{$STORAGEAVAIL3}</td>
  <td>{$STORAGEPERCENT3}</td>
 </tr>
 </table>


I couldnt edit the original post, so I put it here. I hope it didnt cause too many problems.


About the vortexbox.org forum

Most Users Ever Online:

34


Currently Online:

maxtorm

13 Guests

Forum Stats:

Groups: 1

Forums: 4

Topics: 1337

Posts: 7526

Membership:

There are 772 Members

There has been 1 Guest

There is 1 Admin

There are 0 Moderators

Top Posters:

Ron Olsen – 651

HalfBit – 315

jistirling – 226

socistep – 187

JimG – 142

wizardofoz – 133

Administrators: Andrew (1624 Posts)




Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • PDF
  • Propeller
  • Technorati
  • Twitter