#!/usr/bin/perl use Shell; use Getopt::Long; use strict; use warnings; my $usage = "ace-mount-sshfs.pl: Quick way to mount a server via SSHFS\n"; $usage .= "ace-mount-sshfs.pl < --mount> || < --unmount>\n"; my $help = $usage; $usage .= "see --help for more options\n"; $help .= "\t--help Display this help message\n"; $help .= "\t--mount Mount Server to SSHFS \n"; $help .= "\t--unmount Unmount Server from SSHFS\n"; $help .= "\t--server= Remote server to mount (default is chinook)\n"; $help .= "\t--path= Path on remote server to mount (default is sysdev/htdocs/)"; $help .= "\t--port= SSH port to connect do (default is 60022)\n"; $help .= "\t--dir= Local directory to use as mount point (default is /media/wpkg)"; $help .= "\t--user= User to connect as [default=root]\n"; my $helpOpt = ''; my $mount = ''; my $unmount = ''; my $rserver = "chinook"; my $rpath = "/var/www/virtual/acetechgroup.com/sysdev/htdocs/"; my $rport = "60022"; my $ruser = "root"; my $ldir = "/media/wpkg"; GetOptions ('help' => \$helpOpt, 'mount' => \$mount, 'unmount' => \$unmount, 'server=s' => \$rserver, 'path=s' => \$rpath, 'port=s' => \$rport, 'dir=s' => $ldir, 'user=s' => \$ruser); fatal $usage unless ($mount || $unmount || $helpOpt); if($helpOpt) { print $help; exit(0); } elsif($mount) { print "Mounting...\n"; sshfs("-p $rport","$ruser\@$rserver:$rpath","$ldir"); print "$rserver mounted to $ldir\n"; } elsif($unmount) { print "Unmounting...\n"; sudo("fusermount","-u $ldir"); print "Unmounted $rserver from $ldir\n"; }