You can use pidof -x
if you know the process name, or kill -0
if you know the PID.
Example:
if pidof -x rsync >/dev/null
then
echo "Rsync is already running"
exit 1fi
By: rodion and mmoya
Assumed:
First, we need to know what is the device ID of your USB. Plug your USB in.
If you are running VirtualBox on Linux, the USB ID will be something like /dev/sdx (for example /dev/sdb for me).
On Windows, you can see it in the “Disk Management”.
Start typing “dsk” after entering the Start Menu and choose Create and Format Hard Disk Partitions:
Then you will have a page where you can identify the device number of your USB stick or drive.
In my case, my 8GB USB stick is on the Disk 1:
Note that on Ubuntu with VirtualBox 4.0.4 OSE (Open Source Edition): Make sure that you remove the USB device from the “USB Device Filters” list in the machine’s settings (thanks Tim).
Now we are ready to create a Raw Virtual Machine Disk that will link to our USB stick.
Simply open a terminal on linux or a command-line tool on Windows (Win+R cmd) and change directory to your VirtualBox folder.
cd "C:Program FilesOracleVirtualBox"
Then we run the VBoxManage command with the following options to link the USB Drive to a vmdk file (Virtual Machine Disk):
VBoxManage internalcommands createrawvmdk -filename output_usb.vmdk -rawdisk path_to_usb
You need to change the two red color highlighted parts to YOUR settings.
For example on Linux if I want to save in /home/thomas/.VirtualBox/usb.vmdk a virtual machine disk that links to my USB in /dev/sdb, I type the following line:
VBoxManage internalcommands createrawvmdk -filename /home/thomas/.VirtualBox/usb.vmdk -rawdisk /dev/sdb
On Windows, if I want to save the virtual machine disk in C:UsersThomas.VirtualBoxusb.vmdk that links to my USB in in Disk 1 (according to the previous Disk Management), I type the following line:
VBoxManage internalcommands createrawvmdk -filename C:UsersThomasusb.vmdk -rawdisk \.PhysicalDrive1
Replace the 1 in \.PhysicalDrive1 by YOUR device number os the USB drive (for example \.PhysicalDrive2).
VBoxManage internalcommands createrawvmdk -filename "C:Documents and SettingsCarletdesiles.VirtualBoxusb.vmdk" -rawdisk \.PhysicalDrive1
That’s it, you have done a Virtual Machine disk that should be very tiny (~1KB) and links to your USB drive.
You just need to import this hard drive in VirtualBox and use it as primary hard drive (to boot on) for your new system.
By: Thomas
Linux RAM is composed of chunks of memory called pages. To free up pages of RAM, a “linux swap” can occur and a page of memory is copied from the RAM to preconfigured space on the hard disk. Linux swaps allow a system to harness more memory than was originally physically available.
However, swapping does have disadvantages. Because hard disks have a much slower memory than RAM, virtual private server performance may slow down considerably. Additionally, swap thrashing can begin to take place if the system gets swamped from too many files being swapped in and out.
Check for Swap Space
Before we proceed to set up a swap file, we need to check if any swap files have been enabled on the VPS by looking at the summary of swap usage.
sudo swapon -s
An empty list will confirm that you have no swap files enabled:
Filename Type Size Used Priority
Check the File System
After we know that we do not have a swap file enabled on the virtual server, we can check how much space we have on the server with the df command. The swap file will take 512MB— since we are only using up about 8% of the /dev/sda, we can proceed.
df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda 20907056 1437188 18421292 8% /
udev 121588 4 121584 1% /dev
tmpfs 49752 208 49544 1% /run
none 5120 0 5120 0% /run/lock
none 124372 0 124372 0% /run/shm
Create and Enable the Swap File
Now it’s time to create the swap file itself using the dd command :
sudo dd if=/dev/zero of=/swapfile bs=1024 count=2048k
“of=/swapfile” designates the file’s name. In this case the name is swapfile.
—————————————————————————————————————————–
Sizing:
bs=1024: Each block is made of 1024 bytes
count=2048K: There will be 2048K blocks, so
(bs x count) = (1024 x 2,048,000)
This would create a 2 GB swapfile.
—————————————————————————————————————————–
You can change count to 1024K if you want 1 Gigabyte of swap, more than that is not really recommended.
Subsequently we are going to prepare the swap file by creating a linux swap area:
sudo mkswap /swapfile
The results display:
Setting up swapspace version 1, size = 262140 KiB
no label, UUID=103c4545-5fc5-47f3-a8b3-dfbdb64fd7eb
Finish up by activating the swap file:
sudo swapon /swapfile
You will then be able to see the new swap file when you view the swap summary.
swapon -s
Filename Type Size Used Priority
/swapfile file 262140 0 -1
This file will last on the virtual private server until the machine reboots. You can ensure that the swap is permanent by adding it to the fstab file.
Open up the file:
sudo nano /etc/fstab
Paste in the following line:
/swapfile none swap sw 0 0
Swappiness in the file should be set to 10. Skipping this step may cause both poor performance, whereas setting it to 10 will cause swap to act as an emergency buffer, preventing out-of-memory crashes.
You can do this with the following commands:
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
To prevent the file from being world-readable, you should set up the correct permissions on the swap file:
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
By: Digital Ocean
Cron can be touchy when doing multiple operations.
I wanted to use rsync over ssh while passing a password using expect.
The best way to do this is to create a script file and then point cron to the script.
One caveat I ran into is that a timeout needs to be set. This setting needs to be long enough that the files are copied before the timeout occurs.Otherwise you do not copy all of the files.
Here is an example:
#!/usr/bin/expect -f
set timeout 86400
spawn /usr/bin/rsync -e ssh -av user@remotelocation:/remotedirectorylocation /localdirectorylocation
expect {
“*Password:*”
{send “userpasswordr”
}
}
expect eof
exit
Make a mount point:
mkdir /mnt/share
Then, mount your smb share:
mount.cifs //192.168.0.6/sharename /mnt/share -o user=username
It’ll prompt you for a password (you want to stay away from typing passwords within commands when you can!)
Verify it’s mounted by using the mount command:
mount
//192.168.0.6/sharename on /mnt/share type cifs (rw)
Want to do it automagically at every boot? Add it to /etc/fstab:
//192.168.0.6/share /mnt/share smbfs username=rob,password=SuPeRdUpEr 0 0
Now you can rsync stuff to it – let’s rsync rob’s home directory into a dir called ‘homedir’:
rsync -avz /home/rob/ /mnt/share/homedir/
Now, if you really want to get fancy and feel all backed up all the time, add an rsync to crontab!
crontab -e
And add your rsync line to go every night at 2am (or whenever) w/o emailing root anything.
* 2 * * * /usr/bin/rsync -avz /home/rob/ /mnt/share/homedir/ >/dev/null 2>&1
One thing to make sure of though – ensure that your NAS will always come up under that same ip address or your system won’t be able to mount it – and you’ll be rsyncing your home directory into your /mnt/share/homedir on your local system.
By: Rob