tag:blogger.com,1999:blog-16247700039362879382023-06-20T06:19:53.332-07:00Stupid Unix Trickscat haystack | grep needle > !ouchAnonymoushttp://www.blogger.com/profile/14749077400262158300noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-1624770003936287938.post-80606768926113007402011-06-17T09:55:00.000-07:002011-06-17T09:55:17.967-07:00Essential Android ToolsI've been slowly migrating off of doing remote administration from a laptop, and moving almost exclusively to my Android device. I've got a screen in Launcher Pro set up exclusively for system administration related items.<br />
<br />
This is what's on there:<br />
<ul><li><a href="https://market.android.com/details?id=com.adao.android.afm">Adao File Manager</a>: Keep PDFs of documentation in a folder right on your system administration screen<br />
<li><a href="https://market.android.com/details?id=com.google.zxing.client.android">Barcode Scanner</a>: Use it to read those service tags<br />
<li><a href="https://market.android.com/details?id=net.androgames.level">Bubble Level</a><br />
<li>Calculator<br />
<li>Calendar: You do keep a calendar, right?<br />
<li>Camera: Take snaps of screens with error messages on them, use it to note where things are plugged in before you take them apart.<br />
<li><a href="https://market.android.com/details?id=com.intsig.camscanner">CamScanner</a>: Uses the camera as a scanner to create PDFs<br />
<li><a href="https://market.android.com/details?id=com.socialnmobile.flashlight">Color Flashlight</a>: Either use it to illuminate that hard to see part of that rack in that poorly lit closet, or turn it into a rave.<br />
<li><a href="https://market.android.com/details?id=org.connectbot">ConnectBot</a>: Great little SSH Client, also lets you access the console on your phone<br />
<li><a href="https://market.android.com/details?id=com.kodholken.dnslookup">DNS Lookup</a><br />
<li><a href="https://market.android.com/details?id=com.evernote">Evernote</a>: Keeps any random notes on both your phone and the web<br />
<li><a href="https://market.android.com/details?id=com.fsck.k9">K-9 Mail</a>: Best email client out there for IMAP on Android <br />
<li><a href="https://market.android.com/details?id=jp.picolyl.led_light">LED Light</a>: Turns on the LED flash on your camera. Great for nice bright light when you need it.<br />
<li>Maps<br />
<li>Messaging: Nagios notifications<br />
<li><a href="https://market.android.com/details?id=cn.miren.browser">Miren Browser</a>: Best browser currently available for Android<br />
<li><a href="https://market.android.com/details?id=com.overlook.android.fing">Overlook Fing</a>: Network scanner and port scanner<br />
<li><a href="https://market.android.com/details?id=com.mm.network">Ping</a><br />
<li><a href="https://market.android.com/details?id=com.wyse.pocketcloudfree">PocketCloud</a>: Wyse is apparently still around. Free version allows you to connect to one host (either RDP or VNC!) and the Pro version allows multiple hosts.<br />
<li><a href="https://market.android.com/details?id=com.rememberthemilk.MobileRTM">Remember The Milk</a>: Task list on both your phone and the web. You'll need to subscribe to get the Android client, but it is so worth it<br />
<li><a href="https://market.android.com/details?id=com.ceruleanstudios.trillian.android">Trillian</a>: Multi IM Client. Most stable I've tried so far.<br />
<li><a href="https://market.android.com/details?id=jp.eguchi.android.vpnshow">VPN Show</a>: Just puts a shortcut to your VPN connection on the screen, so you don't have to go digging through the menu<br />
<li><a href="https://market.android.com/details?id=com.farproc.wifi.analyzer">Wifi Analyzer</a>: Shows pretty graphs of signal strength. Useful for both analysis and explaining to users why they can't connect to the wifi from the Faraday cage that is their tiny office.<br />
<li><a href="https://market.android.com/details?id=com.benfinnigan.wol">WoL Wake On Lan Wan</a>: Send magic packets to turn on your (appropriately configured) computer<br />
</ul>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1624770003936287938.post-34366388451167699062010-12-21T19:14:00.000-08:002010-12-21T19:14:24.311-08:00APC Network Management Card AP9630/AP9631 Installation Manual is Wrong!I'm sure I'm not the only one that has suffered through this.<br />
<br />
The manual says that "by default, the Network Managemnt Card ignores DHCP offers that do not encapsulate the APC cookie in DHCP option 43" and then proceeds to explain how to disable that requirement in the web interface. Then it gives several examples of alternate ways to configure an IP without the web interface.<br />
<br />
I tried them all but they didn't work. Yeah, so, turns out they didn't work because the system had grabbed a DHCP no problem, without the cookie.<br />
<br />
So, the APC NIC does NOT actually require option 43 to be set on your DHCP server.<br />
<br />
You're welcome!Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1624770003936287938.post-43509473177700979982010-11-12T15:57:00.000-08:002010-11-12T16:12:46.100-08:00LTO Barcodes, for free!Seriously, $100 for *barcode labels*?<br />
<br />
Instead, pick up some sheets of 8"x11" Avery label stock, and print your own.<br />
<br />
This site generates an appropriate PDF to print right on label stock:<br />
<a href="http://tapelabels.librelogiciel.com/">http://tapelabels.librelogiciel.com/</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1624770003936287938.post-25954423801249161942010-10-11T18:45:00.000-07:002010-10-11T18:50:25.133-07:00Automated reboot of Netgear FVG318I'm having trouble with some Netgear FVG318 wireless VPN routers. They can't seem to release their DHCP leases without a reboot, and there's no way to schedule a reboot on them.<br />
<br />
Other than that, these are really great, reasonably priced little devices.<br />
<br />
Hopefully my contacts with Netgear Support will yield a fix so that they don't run out of DHCP leases *for no reason*, but until then I need a workaround.<br />
<br />
So, I used some wget magic to script logging in, saving the necessary cookies, and executing the reboot function.<br />
<br />
Just replace your.fvg318.ip with your FVG318's IP, replace youradminpassword with your admin password. I doubt the line breaks will come out proper in blogspot, so I'll tell you that there is only one line of command between each comment line -- if it line wraps on here, you will need to make sure your copy that you run does not wrap those lines.<br />
<br />
Then just set this up in a cron job to run every night at midnight and voila! No more unhappy uesrs, no more manual reboots.<br />
<br />
<blockquote>#!/bin/sh<br />
<br />
# Load login page<br />
/usr/bin/wget --no-check-certificate -q -O - --save-cookies /tmp/netgear-cookies.txt --keep-session-cookies 'https://your.fvg318.ip/' > /dev/null<br />
<br />
# Log in<br />
/usr/bin/wget --no-check-certificate -q -O - --save-cookies /tmp/netgear-cookies.txt --load-cookies /tmp/netgear-cookies.txt --keep-session-cookies --referer='https://your.fvg318.ip/platform.cgi' --post-data='web0x120010=admin&web0x120011=youradminpassword&umi.loginAuth=Login' 'https://your.fvg318.ip/platform.cgi' > /dev/null<br />
<br />
# Reboot<br />
/usr/bin/wget --no-check-certificate -q -O - --save-cookies /tmp/netgear-cookies.txt --load-cookies /tmp/netgear-cookies.txt --keep-session-cookies --referer='https://your.fvg318.ip/diagnostics.htm' --post-data='umi.restartWrap.x=69&umi.restartWrap.y=14' 'https://your.fvg318.ip/platform.cgi' > /dev/null<br />
</blockquote>Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-1624770003936287938.post-90220865982006589372009-06-11T07:19:00.001-07:002009-06-11T07:21:31.596-07:00In setting up MRTG to work with the NTI Enviromux Mini, I could not for the life of me get it to properly see the vendor's MIB.<br /><br />So, if you're in the same boat, just change appropriate lines in the mrtg.cfg for your enviromux on the Humidity and Temperature lines to match these, to use the numeric OID instead of the name:<br /><br />Target[humsens_1]: 1.3.6.1.4.1.3699.1.1.3.1.3.1.0&1.3.6.1.4.1.3699.1.1.3.1.3.1.0:communitystring@ip:::::1<br /><br />Target[tempsens_2]: 1.3.6.1.4.1.3699.1.1.3.1.2.1.0&1.3.6.1.4.1.3699.1.1.3.1.2.1.0:communitystring@ip:::::1Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1624770003936287938.post-55282407348984237742008-02-18T00:00:00.000-08:002008-03-06T07:47:12.451-08:00Quick tutorial on using viOpen your favorite text file in vi:<br /><br />% vi myfile.txt<br /><br />Navigate to the text you wish to change using hte h, j, k, and l keys<br /><br />j goes down<br />k goes up<br />h goes left<br />l goes right<br /><br />Don't worry...it gets super intuitive after a while!<br /><br />To jump to the last line of the file, type G<br /><br />To jump to the first line of the file, type 1G<br /><br />To insert some text starting at your cursor, type i, then type your text. Press Escape when you're done with your insert.<br /><br />To delete the character under the cursor, type x<br /><br />To undo what you last did, type u<br /><br />To save your file, type :w<br /><br />To save your file and quit, type either :wq or ZZ<br /><br />To save without quitting, type :q!<br /><br />To overwrite a file, even though it's listed as read-only, type :w!<br />The ! means you really, really mean it!!<br /><br />To delete the rest of a word from where your cursor is, type dw<br /><br />To change the rest of the word from where your cursor is, type cw. Press Escape when you're done with your insert.<br /><br />To delete from where your cursor is to the end of the line, type d$<br /><br />To change the text from your cursor to the end of the line, type c$. Press Escape when you're done with your insert.<br /><br />To repeat your last command, type .<br /><br />To search for a string in the file, type /, then type your string. Example: /Target<br />You can use ^string to find a string only at the beginning of the line, and string$ to find a string only at the end of the line.<br />To repeat your search, type n<br /><br /><br />NOW HERE'S WHERE IT STARTS TOTALLY ROCKING!!!<br /><br />To delete from wherever you are, all the way to the next occurance of a string, type d/<br /><br />To change the text from your cursor to the next occurance of a string, type c/<br /><br /><strong>Global search and replace.</strong><br /><br />Type %s/string/somethingelse/g to find all occurrences of "string" and to change it to "somethingelse"<br /><br />The /g on the end makes it do it to the whole file. If you leave that off, it will just do it to the current line.<br /><br /><strong>You can also add multipliers to your commands.</strong><br /><br />To delete from your cursor 5 characters, you don't need to type xxxxx. Just type 5x, and it will do the x 5 times.<br /><br />Same works for changing/deleting words. 4dw deletes 4 words starting at the word you're on.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1624770003936287938.post-71984792955126949552008-02-16T00:00:00.000-08:002009-06-28T19:52:11.622-07:00Microsoft’s User State Migration Tool(This is not a Unix trick)<br /><br />USMT is the User State Migration Tool from Microsoft. It allows you to move whole user profiles from one system to another, copy them from one user account to another user account, or move someone on or off a domain. It's everything I've always wanted in a small-scale user profile manager for Windows. However, USMT is very hard to figure out, and it does not support newer versions of Firefox by default.<br /><br />I've written some batch files to handle the actual command line options for the purposes of copying a domain user's settings from one PC to another, and added an additional configuration XML file to handle Firefox 2.x settings.<br /><br />First, install USMT 3 on a computer. Any computer will do, it doesn't need to be the one you are ultimately using USMT on -- you just need the extracted files.<br /><br />USMT can be downloaded from <a href="http://www.microsoft.com/downloads/details.aspx?familyid=799ab28c-691b-4b36-b7ad-6c604be4c595&displaylang=en">here</a>.<br /><br />The default install will put the files in C:\Program Files\USMT301. Then copy the USMT301 folder onto a USB drive. The whole thing.<br /><br />Put this <a href="http://sites.google.com/site/solenopsis6/Home/custom.xml?attredirects=0">custom.xml</a> file into the USMT301 folder on your USB drive, and put the these two .bat files into the root of your USB drive: <a href="http://sites.google.com/site/solenopsis6/Home/restore-user.bat.txt?attredirects=0">restore-user.bat</a> <a href="http://sites.google.com/site/solenopsis6/Home/save-user.bat.txt?attredirects=0">save-user.bat</a> (rename the files from .bat.txt to .bat).<br /><br />Modify the 2 .bat files, and replace the two "YOURDOMAIN"'s in each file with whatever your domain name is.<br /><br />What you wind up with is a user migration USB drive. For large user profiles, you'll need a large drive. You could specify a network location in the batch files if you like, but in my environment it would be unnecessarily complex to also connect to the network drive while migrating an account (from a possibly dead/dying machine), and we don't necessarily want to be copying large files over the network if we don't have to. Some of my users do video and audio recording, so the profiles can get huge.<br /><br />To use your new user migration USB drive, log in as Administrator on the computer you want to move the user off of, and open the USB drive. Run the save-user.bat file, and type in the user's name. Wait until it is done.<br /><br />Then take the USB drive over to the new machine, log in as Administrator, open up the USB drive, and run the restore-user.bat file, and type in the user's name you want to import the profile into.<br /><br />That is it!!<br /><br />It should restore all the things that USMT is supposed to restore, and it will also do versions of Firefox newer than 1.8.<br /><br />I've tested it with settings for Outlook, IE, Firefox, My Documents files, Desktop files, desktop pattern, and the Windows theme.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1624770003936287938.post-85724092337141073262007-11-05T00:00:00.000-08:002008-03-06T07:47:47.896-08:00Using ls to look at files by the date they were added to your systemThe ls -l command displays fairly detailed information about the files in the directory you are in. It displays the date the file was last modified -- which is known in Unix as the mtime of the file. However, there are other date/time attributes on the file that might be more useful. The mtime doesn't necessarily apply to the file's last modification time on your system -- so if you've deployed an install package, it will probably show you the last time the files were modified on the system on which the package was built. This is sometimes useful for telling how old a version you have, but not really useful for much else.<br /><br />The ctime is the change time, but this is not the same as the file's modification time (mtime). The ctime is the last time the file's <em>status </em> was changed. So, oftentimes this will be the date the file was added to your system. Very useful indeed!<br /><br />This command will display the file's ctime in the date spot instead of the file's mtime:<br /><br /><pre>ls -lc filename</pre><p></p><p>This will show you the directory sorted by the ctime:<br /><br /></p><pre>ls -lct</pre><p></p><p>This will show you the directory sorted reverse by the ctime:<br /><br /></p><pre>ls -lctr</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1624770003936287938.post-4611020042770200472007-06-29T00:00:00.000-07:002008-03-06T07:48:02.894-08:00Wrap long lines using foldTo line wrap a text file at 80 columns, and only break at spaces, use the command:<br /><br /><pre>cat filename.txt | fold -80 -s<br /></pre><p></p><p><i>fold</i> can also be told to wrap at bytes instead of columns, but I've never been quite sure how that would be useful.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1624770003936287938.post-57643327344163488742007-06-23T00:00:00.002-07:002008-03-06T07:48:50.652-08:00Comparing two files using comm<i>comm</i> compares contents of two files. It has 3 columns available in its output — the lines only in file 1, the lines only in file 2, and the lines in both. You'll need to <i>sort</i> both files first.<br /><br /><pre>sort test1.txt > test1-sorted.txt<br />sort test2.txt > test2-sorted.txt<br /></pre><p></p><p>This will show you lines only in test1.txt:<br /></p><pre>comm -23 test1-sorted.txt test2-sorted.txt<br /></pre><p></p><p>This will show you lines only in test2.txt:<br /></p><pre>comm -13 test1-sorted.txt test2-sorted.txt<br /></pre><p></p><p>This will show you lines only common to both files:<br /></p><pre>comm -12 test1-sorted.txt test2-sorted.txt<br /></pre><p></p><p>We can also do some neat tricks with <i>uniq</i>/<i>sort -u</i>:<br /><br /></p><pre>cat test1.txt | sort > test1-sorted.txt<br />cat test1.txt | sort -u > test1-sorted-u.txt<br /></pre><p></p><p>This will show you lines only in test1-sorted-u.txt, which means those are the lines that appear multiple times in your original test1.txt file:<br /><br /></p><pre>comm -13 test1-sorted.txt test1-sorted-u.txt<br /></pre><p></p><p>Neat, huh?</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1624770003936287938.post-75583537593630680082007-06-23T00:00:00.001-07:002008-03-06T07:49:09.931-08:00Setting a lot of user passwords at onceSay you have a whole class of users who have lost their passwords. Or perhaps you've just created a set of users with some automated method that doesn't allow you to easily set their passwords (such as a scriptfile full of useradd commands).<br /><br />You'll want to use a file containing the following information:<br /><br /><pre>user1:passwd1<br />user2:passwd2<br /></pre><p></p><p>Then run the command:<br /></p><pre>cat passwords.txt | chpasswd<br /></pre><p></p><p>Don't forget to delete your passwords.txt file just after you're done. Seriously bad idea to leave this file hanging around.<br /><br />If you're looking for a way to automatically generate a whole bunch of passwords that your users won't balk at, the <i>pwgen</i> command may be installed on your system already!<br /><br />If not, and you don't want to go hunting for one, try this: <a href="http://www.multicians.org/thvv/gpw.html">http://www.multicians.org/thvv/gpw.html</a></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1624770003936287938.post-18142597325975884232007-06-23T00:00:00.000-07:002008-03-06T07:49:26.343-08:00Deleting a large file that’s causing problemsWhen you have a process that's going haywire and filling up a filesystem, you have to remember to kill the process that's accessing/writing the file before the disk space will be freed up.<br /><br />If you're not sure what process that is, use the fuser command:<br /><br /><pre>fuser <i>filename</i><br /></pre><p></p><p>Sure, you can use options in the fuser command to automatically kill off all those processes, but that would make me really nervous if I wasn't absolutely sure what each of them was... killing one of those off could be worse than having a full filesystem.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1624770003936287938.post-982912205589960282007-04-10T00:00:00.001-07:002008-03-06T07:49:51.615-08:00csplit — splitting a text file into multiple separate filesSometimes it's hard to get csv files imported into Excel. Especially if you have a long data file that needs to be separated out into different Excel sheets.<br /><br />If you have data that needs to be in separate documents, and if the different areas in your data file are delimited from each other in some fashion, then you can use <i>csplit</i> to split them into multiple files. csplit means Contenxt-sensitive Split -- there's a command <i>split</i> that will just split the file based on number of bytes, but that's not what we want.<br /><br />For example, if you had a file called input.txt that contains csv formatted spreadsheets, all beginning with the word Sheet by itself on a line, you can run the following command:<br /><br /><pre>csplit -f sheet input.txt /Sheet/ \{99\}<br /></pre><p></p><p>This will split the file into 99 separate files that begin with the line Sheet. It will name them sheet00, sheet01, sheet02, etc. 99 is the max, but you can always run it again on the last file, which would be the remainder of your data after the previous 98 sheets were taken out.<br /><br />It will fail if the number of files you specified is greater than the number of sheets that will be created. So do a grep -c /Sheet/ input.txt beforehand, subtract 1, and use that number. I played around with all sorts of backticks and things to try to get a version of the command that would do this for you, but it really ain't worth it.<br /><br />Sure, given a bit of time you could probably whip up a perl script that would do this better and faster, and probably name the files appropriately. And remove the "Sheet" line while it's at it. But this is already there!<br /><br />As an aside, I always put a space before any numeric codes in csv files that shouldn't be treated like numbers. Especially if they have dashes in them. The space keeps Excel from trying to strip leading zeroes or convert them into dates.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1624770003936287938.post-956528728959895112007-04-10T00:00:00.000-07:002008-03-06T07:50:05.368-08:00grep!<i>grep</i> has a -q (quiet) mode.<br /><br />This is GREAT for use in scripts. If the string you're grepping for gets a match, it returns 0.<br /><br />No fiddling with comparison operators for your if statements!<br /><br /><pre>#!/bin/sh<br /><br />if grep -q needle haystack.txt<br />then<br />echo "I found a needle!"<br />else<br />echo "No needles here..."<br />fi<br /></pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1624770003936287938.post-61930326360788999332007-03-31T00:00:00.000-07:002008-03-06T07:50:28.793-08:00So, it's not a Unix trick, but it's very useful.We've got a bunch of users that we're converting over to Windows domain users. It's tough to move the profiles manually, as there are all manner of shortcuts, Outlook stuff, etc that point to the files in the spot they are now.<br /><br />We found moveuser.exe (in the Windows Resource Kit). But it doesn't work with Administrator accounts! Oh noez!!! Some of our users are logging in as Administrator!<br /><br />The way around it is thusly:<br /><br /><ol><li> Rename the Administrator account (say, to barbarella)<br /></li><li> Create a new administrator account<br /></li><li> Make the old administrator account that the user is using a Restricted User<br /></li><li> Put machine on the domain<br /></li><li> Reboot! not only does the machine need this to get onto the domain, it needs this to see that the old administrator account is no longer an administrator account.<br /></li><li> run 'moveuser.exe barbarella DOMAIN\barbarella'<br /></li></ol>Unknownnoreply@blogger.com0