Saturday, September 14, 2013

Run a Shell script in a Perl script

Call a Bash script in a Perl script
Run a Shell script inside Perl script
Execute Shell script in a Perl script

If you making a perl script and somewhere you want to run a bash script inside that perl script.

It can be done easily through the following piece of code.

Here is a example of an infinite loop in shell script which prints 0 infinite times.
If you run this shell script statement in terminal, it gives you 0 infinite times.
while [ 4 -le 5 ]; do  echo 0;  done;

Suppose I want to run this Shell script from a Perl script, Now I add this line of code in my perl script.

system("bash -c 'while [ 4 -le 5 ]; do  echo 0;  done;'");

Now My Perl script runs this shell script code.

Suppose this line of code is saved in a shell script file as script.sh, now if I want to run this shell script from my perl script.

I simply add this line of code in my Perl script.
system("bash -c '/root/Desktop/url.sh'");

Thursday, August 29, 2013

E: Sub-process /usr/bin/dpkg returned an error code (1)

E: Sub-process /usr/bin/dpkg returned an error code (1)

If you are installing any package in Ubuntu or Debian and it gives above error

Solution : 1
Run following command in terminal
sudo dpkg --configure -a
Now try to install your package again.

Solution : 2
Run following command in terminal
sudo apt-get -f install
Now try to install your package again.

Solution : 3
Open file /var/lib/dpkg/status and remove the whole block of corrupted packages.
Now try to install your package again.

Format USB pen drive using command line on Linux


Format USB pen drive on Linux

First find the device path of the USB device using following command
fdisk -l
Output looks like this.

Now you can find the device path of the USB drive.
Suppose it is /dev/sdb1

Format pen drive in fat32 filesystem, Run following command
mkdosfs -F32 -v -n "" /dev/sdb1

Format pen drive in NTFS filesystem, Run following command
mkntfs -Q -v -L "" /dev/sdb1

Format pen drive in ext4 filesystem, Run following command
mkfs.ext4 -j -O extent -L "" /dev/sdb1

Format pen drive in ext3 filesystem, Run following command
mkfs.ext3 -L "" /dev/sdb1

Format pen drive in ext2 filesystem, Run following command
mkfs.ext2 -L "" /dev/sdb1

Format pen drive in fat16 filesystem, Run following command
mkdosfs -F16 -v -n "" /dev/sdb1

Note :
Change /dev/sdb1 with your device path.