RSSCategory: Geekery

Is there a file in that folder?

If you need a script to find if there is a file in a folder or perhaps you are checking for the existence of a file in a specific location.



#!/bin/bash
FILE=”/DIRECTORY/FILENAME”
if [ -f $FILE]; then
echo “Yep that file is there
else
echo “Oh no file with that name found”
fi
exit

Sorted.

August 12, 2014 | By | Reply More

is that directory empty?

I needed a quick and dirty way to find if the contents of a directory is empty. I’m not interested in th hidden files only files or orther directories within. Here is the bash script i knocked up to do the check…

#!/bin/bash
DIRECTORY=“/SOMEWHERE/”
if[ “$(ls -A $DIRECTORY)”]; then
echo”$DIRECTORY is not empty!”
else
echo”$DIRECTORY is empty!”
fi
exit

Job done.

August 8, 2014 | By | Reply More

Timemachine on ReadyNAS

Currently my ReadyNAS is running firmware version 4 and so will not bind to my MAC OS X mavericks Server. I am planning to upgrade to version 6 of the ReadyNAS firmware when I have confirmed that the binding will function as expected. So for now the steps below enable me to have a user share which contains the TimeMachine Backup which I can control with quotas’ on the ReadyNAS.

The steps below assume that Time Machine support is already enabled on the ReadyNAS.

Go into FrontView. Under Security > User Accounts I added a user account for each computer with a quota. Aa I have 9TB of storage so I tend to allocate at least 1.5x the computer’s hard drive space for backups and for each user, only two files needed to be created. I am working on a bash script that will automate this process. Please not that the quota you set is counted against all the users files and not just the TimeMachine Backup. I do understand but I have yet to test this, that the .AppleVolumes file created below can contain volsizelimit:size in MiB option. This would be helpful to set the 1.5 times HDD size but set the quota on the ReadyNAS to a larger size.

Repeat the following steps for each user you create:

Open a Finder window and open the AFP (or CIFS) representation of your ReadyNAS in the sidebar or Network folder.

You’ll probably be connected as “Guest” and might see any shares that are publicly accessible. Click the “Connect As” button at the top of the window and connect using one of the user accounts you created earlier.

A folder should show up with the name of the user that you logged on as. That’s the user’s home folder.

Using your favorite plain-text editor create a new plain-text file with a single line containing: (I have added the volsizelimit as I mentioned above. If you don’t need it the remove volsizelimit:500000 from below.)

/c/home/USERNAME ReadyNAS cnidscheme:dbd allow:USERNAME volsizelimit:500000 options:tm 

Note: Replace USERNAME with the exact spelling of the user you’re connected as. (It should match the folder name in case and spelling.) Save this file as .AppleVolumes in the user’s home folder.

Create an empty file called .com.apple.timemachine.supported and save it in the user’s home folder.

Note: both the files start with a . which won’t show up in the Finder normally. Eject the ReadyNAS share when you’re done creating those two files and connect as the next user if necessary. I found I didn’t have to reboot the system to make the changes work for the next step. But it doesn’t hurt.

On your Mac, go into the Time Machine preferences. If Time Machine was already setup, go to Select Disk and choose “Do Not Backup” (this makes it forget the previous username/password that was saved). Then do Select Disk again and choose your ReadyNAS like usual. When asked for a username and password, connect using the user and password you setup for that particular user on the ReadyNAS.

July 8, 2014 | By | Reply More

Adjusting the SUDO timeout

While the sudo flags are convenient, there may be times when you might forget to use these flags. Alternatively, you might wish to have the time-out be longer if you are not concerned about security and regularly find yourself needing to supply your password when running sudo commands. Therefore, you can change the default time-out for sudo to be shorter, longer, or even to disable it altogether and always require a password when running sudo.

To do this, you can specify a custom time-out by editing the sudo configuration file by opening the Terminal and then running the following procedure:

  1. Run the command “sudo visudo” to invoke the sudo configuration editor
  2. Press “i” to invoke “insertion mode” so you can make edits
  3. Use arrows to navigate to the section “# Defaults specification” which will have a number of lines that begin with “Defaults” below it.
  4. Change the line that states “Default env_reset” to have “,timestamp_timeout=NUMBER” (with NUMBER being the number of minutes to time-out) appended to it, so it reads like the following (in this example the number is 2 minutes—if you always want sudo to require a password then set this value to 0):Defaults env_reset,timestamp_timeout=2
  5. Press escape to exit insertion mode
  6. Press “:” followed by typing “w” then “q” and then press enter to save and quit

As always, before making any changes to system configuration files be sure to have a backup of your system (even though “visudo” will create an automatic backup of the sudoers file). To undo these changes, simply invoke the visudo editor again and remove these edits.

 

June 9, 2014 | By More