You are not logged in.
I've got a few samba shares set up on a server in my back room. I'd like to mount several of them on my laptop in one go with a bash script. I've got a very baisic programming background and know virtually nothing about writing a bash script. Between researching google and various linux forums I've came up with this so far. Any help or guidance would be greatly appreciated.
echo "Enter root password."
read PASSWORD
VAR=$(expect -c '
send "sudo mount -t cifs //Server/Share /mountpoint"
expect {
"Prompt#" { send $PASSWORD }
}
send "sudo mount -t cifs //Server/Share /mountpoint"
expect {
"Prompt#" { send $PASSWORD }
}
send "sudo mount -t cifs //Server/Share /mountpoint"
expect {
"Prompt#" { send $PASSWORD }
}
send "sudo mount -t cifs //Server/Share /mountpoint"
expect {
"Prompt#" { send $PASSWORD }
}
')
Offline
You're doing this the hard way
Have a look in /etc/fstab
//Server/Share1 /mountpoint1 cifs noauto,user,soft,nocase,credentials=/etc/cifs.creds 0 0
//Server/Share2 /mountpoint2 cifs noauto,user,soft,nocase,credentials=/etc/cifs.creds 0 0
//Server/Share3 /mountpoint3 cifs noauto,user,soft,nocase,credentials=/etc/cifs.creds 0 0
Then you can mount simply by running:
mount /mountpoint1
mount /mountpoint2
mount /mountpoint3
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
#!/bin/bash
sudo mount -t cifs //Server/Share1 /mountpoint1
sudo mount -t cifs //Server/Share2 /mountpoint2
sudo mount -t cifs //Server/Share3 /mountpoint3
It will ask you for your password, because the only environment you would want your script to be run, is an interactive shell. But, seriously:
#!/bin/bash
mount -t cifs //Server/Share1 /mountpoint1
mount -t cifs //Server/Share2 /mountpoint2
mount -t cifs //Server/Share3 /mountpoint3
Throw it in /usr/local/bin and run it with "sudo myscript".
Or, yes, fstab…
Offline