Archive for March, 2012

automatically adding the unix users to the samba smb.conf shares

With the following script we can automatically add shares to the smb.conf (/etc/samba/smb.conf) based on the actual unix users:

#!/bin/bash

writesmb()
{

echo "[$f]" >> /etc/samba/smb.conf
echo " read only = no" >> /etc/samba/smb.conf
echo " valid users = $f" >> /etc/samba/smb.conf
echo " path = /home/$f" >> /etc/samba/smb.conf
echo " create mask = 0777" >> /etc/samba/smb.conf
echo " directory mask = 0777" >> /etc/samba/smb.conf
echo "" >> smb.conf
}

for f in $( ls /home ); do writesmb; done

Removing specific occurrences of files

Hi,

let’s say we have a Linux file server (samba) and the users insist in keep adding mp3 files into it. With the following command (and I suggest you adding the script to your crontab) we can remove all the occurrences of mp3/MP3 files everyday without doing it manually.

#find /home -type f -iname "*.mp3" -exec rm -fv {} \;

Where “find /home” will search recursively in your home directory, looking for “files” only (-type f) for the all the files containing the last characters as “mp3 or MP3” and then it will remove all these results (rm -fv).

adding standard samba password to a user list

In my workplace we had about 55 users and we needed to set a standard password for all these users (of course we would let them modify it for a secret password after the first login). I am lazy, therefore I didn’t want to set a standard password one by one. With the code below it was possible to get each user listed in the file users.txt and set the standard password “pass” for each one of them.


for f in $( cat /root/users.txt ); do echo -ne "pass\npass\n" | smbpasswd -a -s $f; done

Of course, alternatively, I could use “ls /home” instead of “cat /root/users.txt”.