Archive for ‘Shell Script’ Category
Posted on 20:22, March 8th, 2012 by Many Ayromlou
If you’ve enabled MediaServer and/or PhotoStation on your Synology NAS you might have noticed a bunch of “@eaDir” folders inside your data folders. You will not normally see this under samba or appletalk connections. I noticed it since I was trying to rsync from synology to a old qnap nas I have lying around. Although you can turn these services off from the Control Panel, it does not get rid of these dumb folders. So here is a quick script to clean all the “@eaDir” folders up from your synology disk. NOTE: I’VE INTENTIONALLY NOT USED THE “rm -rf” COMMAND HERE. I DON’T WANT YOU TO DESTROY YOUR NAS SERVER WITH JUST ONE COMMAND. Run the command below and it will “echo” the names of these “@eaDir” folders to the terminal. Then once you’re satistied that it’s working well (no weird filenames/characters/etc.), then replace the “echo” with “rm -rf” to actually remove those folders. There is no guarantee that this will work for you, DO NOT USE THIS IF YOU DON’T UNDERSTAND WHAT THE COMMAND DOES. THIS CAN HARM YOUR FILES.
Make sure you login via ssh first and “cd” to where your files are stored. This command starts looking for “@eaDir” folders recursively from the current directory.
Okay, now for a bit of CLI goodness. Here is a quick list of basic apt commands. Debian and most derivatives (Ubuntu) use these for package maintenance.
#get source code
OSX Webmaster special: Shared webserver, bad umask settings, group permissions and filenames with spaces…
Posted on 12:20, October 24th, 2007 by Many Ayromlou
Okay so this all started with our users not being able to share files on our webserver. We use SSH only for upload/download and interactive access (ie: no ftp). Through trial and error we found out that the default umask (under OSX Server) for sftp uploaded files are 0033 (ie: rwxr–r–) and directories are 0022 (ie: rwxr-xr-x). This creates a problem when one user uploads a file and another user downloads/modifies and tries to re-upload it — they simply can’t because the group permissions are wrong.
If we were using ftp (which we are not) there are some solutions on the net that allow you to modify the startup parameters for the ftp server so that the default umask for all files is 0013 — which would allow a group of people to share/overwrite each others files — but we are using ssh only.
So we came up with two other solutions — a shared upload account and/or a cron job that would modify the group permissions on the website directory to allow group sharing. We went with the second solution and that’s where I ran into so many problems that I decided to create this post. You see normally Unix users know that spaces (and strange characters) in filenames are a no-no. Well that’s not true for Windows and Mac users, they use spaces and other odd characters in their filenames/folders all the time.
I started writing — what I thought was — a simple “for loop” script to go through the website folder and change the group permissions. Of course on the first try things didn’t work nicely because of spaces, so I started compensating for that and came up with:
Finally after a latenight RTFM session (and lots of cursing), I think I’ve found the ultimate file handling loop statement:
After trimming and optimizing the script a bit, here is the final product:
Posted on 18:41, August 4th, 2007 by Many Ayromlou
Here is a easy way to copy an entire directory tree from one Unix machine to another, while retaining the permisssions and ownership, using ssh as the middle man. Assuming that you want to copy everything under source_directory to destination_directory on another machine here is the command you would issue on the source machine (first cd to the directory containing source_directory):
One last command which I came across the other day…..If you’re ever in need of a stop watch just use your shell to measure time. Issue the following command and wait a bit. Now interrupt it via Ctrl-C and it will show you how much time has passed. NOTE: Nothing happens when you issue the command, only when you stop it via ctrl-c.
Okay these are bash goodies, so they’ll work in any environment. If you’re in a situation where you’re switching between two different directory paths over and over again, here is a quick tip
Posted on 16:42, July 23rd, 2007 by Many Ayromlou
Before I start, this tip is Unix friendly (not just OSX), but requires you to know what shell scripts are and how you create/run them. Additionally you should be familiar with the workings of the “find” command in Unix.
I had lots of trouble getting the Google Analytics code onto my gallery site. The problem is that I use iWeb to create a front end that links to a discrete back end (ie: specific subdirectories generated by Photoshop, iPhoto or Aperture). I found this Automator script earlier, but it seems like every time I run the script on a Folder, the script only changes .html pages created by iWeb….Weird. So after some head scratching and googling, I found the following complementary scripts on RSVP – Xnews site. There is a certain amount of detail about what the script is actually doing on that site, but I just wanted to extract the meat and add a little garnish (yeah I made a couple of mistakes, that I hope you’ll avoid).
At this point you should have three scripts insert, remove and delback. Use insert to insert the code into all the HTML files under a certain path ($WebPath). This will create .bak files and once you’ve verified the insert scripts operation you can delete/clean them using the delback script. Use remove to remove the analytics code from your HTML pages (if you decide later that you don’t like google analytics or something). Again this process creates .bak files that can be removed/cleaned using the delback script.
Keep in mind also that if you use iWeb to generate your pages and they are sitting on a OSX server that by default your web addresses get expanded after the browser requests them (ie: My gallery is http://www.rcc.ryerson.ca/~mayromlo but gets expanded and rewritten as http://www.rcc.ryerson.ca:16080/~mayromlo/Site/Welcome.html). So you need to get google analytics to go to the expanded version by editing the profile information after initial entry and changing the website URL. This last issue is very mac/osx specific.