I want to save this little trick for later. To get vi(m) to show line numbers, use the following command:
:set nu
Hit escape first in case you’re in input mode. Then simply type the colon set nu and hit enter.
I want to save this little trick for later. To get vi(m) to show line numbers, use the following command:
:set nu
Hit escape first in case you’re in input mode. Then simply type the colon set nu and hit enter.
When Xenserver 7 came out I found myself unable to easily upgrade to it thanks to my custom RAID 1 build. If I wanted Xenserver 7 I would have to blow the whole instance away and start from scratch. This posed a problem because I have a pool of 2 xenserver hosts. You cannot add a server with a higher xenserver version to a lower versioned pool; the pool master must always have the highest version of Xenserver installed. My decision to have an mdadm RAID 1 setup on my pool master ultimately turned into forced VM downtime for an upgrade despite having a pool of other xenserver hosts.
After transferring VMs to my secondary host and promoting it to pool master, I wiped my primary xenserver and installed 7. When it was up and running I essentially had two separate pools running. To transfer my VMs back to my primary server I had to resort to the command line.
The xe vm-export and vm-import commands work with stdin/out and piping. This is how I accomplished transferring my VMs directly between two pools. Simply pipe xe vm-export commands with an ssh xe vm-import command like so:
xe vm-export uuid=<VM_UUID> filename= | ssh <other_server> xe vm-import filename=/dev/stdin
Note the lack of a filename – this instructs xenserver to pipe to standard output instead. Also note that transferring the VM scrambles the MAC addresses of its interfaces. If you want to keep the MAC address you’ll have to manually re-assign it after the copy is complete.
For the method above you will have to turn the VM off in order to transfer it. I had some VMs that I didn’t want to stay down for the entire transfer. A way around this is to take a snapshot of the VM and then copy the snapshot to the other pool. Note that this method does not retain any changes made inside the VM that occurred after you took the snapshot. You will have to manually transfer any file changes that took place during the VM transfer (or be fine with losing them.)
In order to export a snapshot you must first convert it to a VM from a template (thanks to this site for outlining how.) The full procedure is as follows:
xe vm-snapshot uuid=<VM_UUID> new-name-label=<snapshotname>
xe template-param-set is-a-template=false ha-always-run=false uuid=<UUID of snapshot>
xe vm-export uuid=<UUID of snapshot> filename= | ssh <other_server> xe vm-import filename=/dev/stdin
I used both methods above to successfully move my VMs from my older 6.5 pool to the newer 7 pool. Success.
I’ve recently upgraded to the latest version of Citrix Xenserver 7 (codenamed “Dundee”.) 7 is based on CentOS 7 and has a massive amount of changes under the hood. One such change was how they handle PCI Passthrough.
It took some time to figure PCI Passthrough out. 7 uses grub instead of extlinux for the bootloader. It appears to be grub2 but they don’t use the standard update-grub tool, rather you simply edit the config file and do nothing else.
After much searching I found this post which led me in the right direction. In Xenserver 7, for pci passthrough support you must do the following:
xe vm-param-set other-config:pci=0/0000:B:D.f uuid=<vm uuid>
xen-pciback.hide=(B:D.f)
You will now be able to pass through hardware to your virtual machines in Xenserver 7. Hooray.
When trying to update crouton I kept getting the following error message:
Preparing to unpack .../linux-image-3.8.11_20150314_amd64.deb ... Ok, aborting, since modules for this image already exist. dpkg: error processing archive /var/cache/apt/archives/linux-image-3.8.11_20150314_amd64.deb (--unpack):
After some digging I found this thread which explains how to fix it. The source of the problem was the fact that I had installed a modified kernel to allow VirtualBox to work properly. The way to update crouton is to remove the repository for that kernel
rm /etc/apt/sources.list.d/crouton-packages.list
After removing that repository the update completed successfully.
IrfanView is a very versatile little program that you can use to manipulate and view image files. I am very familiar with it and often find myself wishing I could use it in Linux. Well, it turns out I can!
There are a few things you need to do. First, install wine
#For debian-based distros sudo apt-get install wine
After wine is installed, use it to install irfanview
wine iview442_setup.exe
If you get the following error, it means you don’t have mfc42.dll installed:
err:module:import_dll Library MFC42.DLL (which is needed by L"Z:\\home\\nicholas\\Downloads\\iview442_setup.exe") not foun
The solution is to use winetricks to install mcf42.dll (thanks to winehq for the soultion to this)
winetricks -q mfc42
Optionally you can make wine your default image program (or just have it in the list of available image handling programs.) The way to do this is to write a quick script and mark it executable (thanks to linuxquestions for the answer on how to do this)
#!/bin/sh IRFANVIEW="C:\\Program Files\Irfanview (x86)\i_view32.exe" ROOT_DRIVE="Z:\\" for arg do wine "$IRFANVIEW" "${ROOT_DRIVE}$(echo "$arg" | sed 's/\//\\/g')" done
You may need to tweak it a little bit if you don’t have 64bit wine installed. Save that file somewhere you will remember and then mark it executable with chmod +x.
Lastly, when you right click a file and do open with, simply point it to the above script. The result: wine goodness.
For some reason I had a hell of a time finding a way of excluding a directory from the ‘find’ command. I finally found a solution that works thanks to this website.
The solution for me was to add the following to my find command:
! -path "<directory to exclude>"
So to find all files modified less than 24 hours ago on my grandmother-in-law’s computer, I used the following command:
find . -mtime -1 ! -path "./AppData/*"
Grandma’s computer runs Windows 7 but I’ve configured Cygwin and ssh so I can use the tools I’m fimilar with. The above command excludes appdata and searches her user profile for all files modified today.
Over the years I’ve needed to access family members’ machines for remote support. The problem with parents and grandparents is walking them through certain prompts for services like join.me is quite problematic. To that end I’ve devised an open source way for me to automatically remote into their machine regardless of firewalls or machine location. This is possible thanks to cygwin, autoSSH, and NSSM. As long as the machine has internet access, I can get to it.
To pull this off you’ll need to install a few cygwin packages, copy over a private key file, create a batch script, and invoke NSSM to create a service to invoke the batch script on startup.
Obtain cygwin from here. You’ll need to use the graphical installer for the initial setup. Install the following packages:
If cygwin is already installed, install it again. I wasted an hour once trying to figure out why it wasn’t working when the culprit turned out to be a buggy old version of cygwin itself.
For this to work you’ll need an SSH server configured for key authentication (no password.) On your SSH server:
One option that I really enjoy on my SSH server is the GatewayPorts option. This turns your SSH server into a gateway for any port forwards. Simply edit /etc/ssh/sshd_config and add
GatewayPorts yes
Save the file and restart the SSH service. Now if you create SSH tunnels your SSH server opens those ports for you to connect from other machines.
On the windows machine a simple command gets us up and running. Create a one-liner .cmd file on the Windows machine in a location of your choosing with the following:
c:\cygwin\bin\autossh.exe -M <random_port_number> -i <keyfile location> -l <user> -R<remote_port:localhost:<local_port> -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null <remote address>
Update it to reflect the path of your cygwin installation if you installed somewhere other than the default location.
I add the reverse port forward option ( -R ) so that I can simply connect to my ssh server on the specified port and the connection will tunnel through to the Windows computer. In my case, I do -R5700:localhost:5900 which instructs my ssh server to listen on port 5700, then forward that connection to the Windows machine on port 5900 for VNC.
The Non-suciking service manager is a nifty little program that lets us turn anything into a windows service. Once it’s a service it can be started automatically on startup, even if nobody has logged in yet.
Obtain NSSM from here and extract it to a location you can remember. Then, open an administrator command prompt, cd to the directory containing nssm.exe, and enter the following:
nssm.exe install autossh
A GUI will open up. Specify the location of your batch file in the Path: section, then click Install service.
Once this is done, start the service by running services.msc, looking for your service, right click and select start. Make sure the startup type is set to automatic.
That’s it! If your keys are in the right place and the permissions are correct, the computer will automatically (and silently) log into your SSH server and create a tunnel for you. Autossh will continually try to re-connect in the event of connection loss. Awesome.
You can also configure cygwin to be an SSH server for your windows host. This will allow you to SSH into the machine if you specify -R<random_port:localhost:22 in your batch file. Here are a few notes for getting ssh working
ssh-host-config
My parents got a shiny new Netgear R80000 wireless router which supports OpenVPN out of the box. The client configuration it generates doesn’t work right away, though, when I try to connect from my Linux Mint desktop. The connection is successful but I can’t ping or reach anything on the other network.
I discovered on this forum that you must add a couple options to the config file the router produces. You can do this either on the command line or by modifying the config file. The options are to add an interface to the VPN and to create a route to the network, like so:
--ifconfig 192.168.1.5 255.255.255.0 --route 192.168.1.1
I took the generated non-windows VPN configuration from their router, unzipped it on my linux desktop, and then ran this command:
sudo openvpn --config parents.ovpn --ifconfig 192.168.1.5 255.255.255.0 --route 192.168.1.1
It worked like a charm.
For some time now Splunk has been alerting me to “missing” forwarders even though all of those forwarders are working perfectly fine. It turns out to be a glitch in the Deployment Monitor app. After much digging I found this Splunk article which explains it:
https://answers.splunk.com/answers/188784/after-update-to-splunk-enterprise-62-why-does-the.html
The fix is fairly simple, thankfully. You have to edit the macros.conf of the Deployment Monitor app to add this small snippet right before the first pipe:
NOT eventType=*
The default path for this configuration file is:
/opt/splunk/etc/apps/SplunkDeploymentMonitor/default/macros.conf
The relevant stanza in my macros.conf is below:
[forwarder_metrics] definition = index="_internal" source="*metrics.log" group=tcpin_connections NOT eventType=* | eval sourceHost=if(isnull(hostname), sourceHost,hostname) | eval connectionType=case(fwdType=="uf","universal forwarder", fwdType=="lwf", "lightweight forwarder",fwdType=="full", "heavy forwarder", connectionType=="cooked" or connectionType=="cookedSSL","Splunk forwarder", connectionType=="raw" or connectionType=="rawSSL","legacy forwarder")| eval build=if(isnull(build),"n/a",build) | eval version=if(isnull(version),"pre 4.2",version) | eval guid=if(isnull(guid),sourceHost,guid) | eval os=if(isnull(os),"n/a",os)| eval arch=if(isnull(arch),"n/a",arch) | fields connectionType sourceIp sourceHost sourcePort destPort kb tcp_eps tcp_Kprocessed tcp_KBps splunk_server build version os arch guid
I recently needed a quick and dirty way to crop the bottom chunk of a large batch of scanned photos. Thanks to Linux and FOSS, this is possible with a fantastic tool known as imagemagick.
Simply install imagemagick to get the necessary tools
#Assuming you have a redhat based distro sudo yum install ImageMagick*
Once installed use the mogrify tool (part of ImageMagick) to quickly chop the bottom part off:
mogrify -chop 0x45+0+0 -gravity South *.jpg
The above example chops the bottom 45 pixels off of every picture in the directory you’re in. Thanks to this site for the info. Handy.