CopyDisable

Showing posts with label Operating System. Show all posts
Showing posts with label Operating System. Show all posts

Tuesday, 16 May 2017

Encrypting the shell scripts

Sometimes we need to encrypt a shell script for security reasons, for example if the script contains some sensitive information like password etc.
For this task I am going to use the shc tool (http://www.datsi.fi.upm.es/~frosal/sources/shc.html) to convert my text shell script file into a binary file . Download the source code of shc tool from the link http://www.datsi.fi.upm.es/~frosal/sources/ and extract the GZIP compressed tar archive file. Here I am going to use the 3.8.9 version.
Note: I used Ubuntu 14.04 for this example.
If make is not installed, then install make
# apt-get install make
Go inside the shc-3.8.9 source folder.
# cd shc-3.8.9
# make


clip_image001
Now install shc
#make install
clip_image003
If installation fails with directory not found error, create the /usr/local/man/man1 directory and run the command again.

#mkdir /usr/local/man/man1
# make install

clip_image004
Remove the shc source folder after it is installed
# cd ..
# rm -rf shc-3.8.9/

Our shc tool is installed, we are now going to convert our shell script into binary.
Go to the folder where the shell script is stored. My script name is mysql_backup.
Create binary file of the shell script using the following command:
# shc -f mysql_backup
shc command creates 2 additional files
# ls -l mysql_backup*
-rwxrw-r-- 1 pranab pranab 149 Mar 27 01:09 mysql_backup
-rwx-wx--x 1 pranab pranab 11752 Mar 27 01:12 mysql_backup.x
-rw-rw-r-- 1 pranab pranab 10174 Mar 27 01:12 mysql_backup.x.c
 
mysql_backup is the original unencrypted shell script.
mysql_backup.x is the encrypted shell script in binary format.
mysql_backup.c is the C source code of the mysql_backup file. This C source code is compiled to create the above encrypted mysql_backup.x file.
We will remove the original shell script (mysql_backup) and c file (mysql_backup.x.c) and rename the binary file (mysql_backup.x) into the shell script (mysql_backup).
# rm -f  mysql_backup.x.c
# rm -f mysql_backup
# mv mysql_backup.x mysql_backup
 
Now we have our binary shell script, the contents of this file can not be easily seen as it is a binary file.

Monday, 15 August 2011

Changing remote computer’s IP configuration from command line

1) I used PsExec tool to run command in a remote computer. It can be downloaded from http://download.sysinternals.com/Files/PsTools.zip
PsExec tool execute a process on a remote computer.
Syntax: psexec \\computer[,computer[,..] [options] command [arguments]


2) Now the command I will use to change the IP configuration is netsh.
netsh is a command-line tool for updating Windows network configuration settings. It also has options for configuring remote systems but in this example I am not going to use that.
We can also use netsh to find the IP configuration information.


3) We can even use it to enable or disable windows firewall.
For Windows XP use the following:
 For Windows Vista and above:


4) To change a computer’s network adapter to use static IP address:
I have configured vaibhav’s adapter with the static IP 172.16.0.44 netmask 255.255.255.0 and default gateway 172.16.0.3.



5) To change a computer’s network adapter to use dynamic IP address from DHCP server:




netsh command is wonderful and it has many options. Explore it to enjoy its full functionality.


জয় আই অসম,
প্রণব শর্মা

Sunday, 14 August 2011

Small Trick to open the windows command prompt

Scenario: We had a problem in one of our servers. We were not able to run any executable file from windows run, from the task manager New task (run…), using the shortcut on the desktop, or from the Start menu. The registry entries for the executable files were damaged. We were not able to run the registry editor, windows explorer, command prompt etc. We could not run any tool, antivirus etc. I used one trick to open the command prompt, using the command prompt I was able to install and run a web-browser, after that I could download and install antivirus etc. and run them from command prompt.
It is very very simple and I think it may be useful for us in future.
The trick:
Right Click on any file like text file, image file etc. and select open with command processor












So here is my command prompt 1,  and I can do my stuffs now 36.


জয় আই অসম,
প্রণব শর্মা

Friday, 12 August 2011

Disk space error when installing RHEL 4


While installing RHEL 4 I was getting ?An error occurred transferring the install image to your hard drive.
You are probably out of disk space?
error. But in my hard disk I have
enough space for installation. So I was sure that this problem is not due to
shortage of disk space.
I searched for this problem and found some solution:
1.   
When starting the installer enter the command:
linux allowcddma

2.   
If the above command doesn?t work use the
following command:
linux mem=128M
If 128M doesn’t work, try smaller numbers.

3.  
Sometimes this problem comes due to defective
CDs. Do media checking at the time of installation.


In my case linux allowcddma worked for me.

জয় আই অসম,
প্রণব শর্মা

Thursday, 11 August 2011

Shutting a computer remotely using Microsoft Management Console (MMC)

1) Open computer management console (Right-click the My Computer desktop icon and select Manage), then right-click Computer Management(Local) and select Connect to another computer. Enter/select the remote system you want to restart. Click OK



2)After getting connected to the remote computer, right-click Computer Management and select Properties



3) In the Computer Management properties window, go to the Advanced tab.  



4) Click the Settings button in Startup and recovery. 



5) Click on Shut Down button. The Shut Down window has different shutdown options. Select the option as per requirement and click OK. 



জয় আই অসম,
প্রণব শর্মা
 

Adding a SCSI Disk to a computer running Linux

Scenario: There is a SCSI disk with NTFS partition and this disk is to be added to a Linux box.
 
Step 1: Connect the SCSI disk to the Linux box.
 
Step 2: Type the command
#fdisk –l


 It will display partitions on all available disks, note the device name for the SCSI disk. Suppose the device name is /dev/sdb
 
Step 3: Start fdisk with /dev/sdb as argument
#fdisk /dev/sdb 

 Step 4 : To print the partition table for this disk
Command (m for help):


Device Boot Start End Blocks Id System
/dev/sdb1 * 1 4462   7 HPFS/NTFS
/dev/sdb2   4463 8924   F Win 95 Extended
/dev/sdb5   4463 8924   7 HPFS/NTFS
 
 
Step 5: Delete the partitions
Command (m for help): d
partition number (1-5): 1

Command (m for help): d
partition number (1-5): 2



Step 6: Create the required partitions (I will create one logical partition and will add that into my existing Linux file system)

Command (m for help): n

Command action
e extended
p primary partition
e
partition number (1-4): 1

Command (m for help): n
Command action
l logical (5 or above)
p primary partition
l
 
Step 7: Now I have created the required partition table for the disk, now I have to write the partition table to the disk.
Command (m for help): w
 
Step 8: View the new disk partition
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sdb1   1 8924   5 Extended
/dev/sdb2   1 8924   83 Linux
Quit fdisk program
 
Step 9: Format that partition and make file system
#mkfs.ext3 /dev/sdb2
 
Step 10: Create a directory to mount the partition
# mkdir /new_partition
 
Step 11: Mount the partition
#mount –t ext3 /dev/sdb2 /new_partition
 
Step 12: Add an entry in the /etc/fstab file so that the partition automatically gets mounted
/dev/sdb5 /new_partition ext3 defaults 1 2



জয় আই অসম,
প্রণব শর্মা

Monday, 8 August 2011

Using Partimage

The Partimage is a Linux utility which can be used to save disk partitions into an image file. It only copies the used blocks of a partition. It can also compress the image file with gzip/bzip2 utilities to reduce the image size. It supports many file systems. Following is the list of supported file systems at the time of writing this document (only the stable supports are included in the list):

Name Description
Ext2fs/Ext3fs Linux file system
Reiser3 A journalized and powerful file system
FAT16/32 DOS and Old Windows file systems
HPFS IBM OS/2 File System
JFS Journalized File System, from IBM, used on Aix
XFS Journalized File System, used on Irix


It can be downloaded from http://www.partimage.org/Download or it can be installed using apt-get


I will show the use of partimage with an example.

Scenario:
One of my machine’s OS crashed and I am unable to repair it, I need the data in the disks of the machine. So I booted the machine with Ubuntu Linux live CD and mounted an USB disk. I will clone the partitions using partimage and I will store the disk images into the USB disk. I will restore the partition images into a different machine.



Example:

I have mounted the USB disk to /media/disk folder.

Before starting Partimage use fdisk command to find the information of the existing partitions in the system
# fdisk –l

Note the name of the partition to be cloned using partimage.

To start PartImage run the command
$ sudo partimage or
if you have login as root
# partimage





Creating Image

I am going to clone the sda5 partition. Select sda5 partition in the Partition to save/restore list.
Enter the name and location of the image file (I have specified the location in the USB disk) in Image file to create/use.
The name of the image file is specified as image. The file will be created as image.000. I can split the image file into multiple files (this option is in the next screen), in that case the files will be created as image.000, image.001 and so on.
Select Save partition into a new image file in Action to be done
Partimage can save image over the network using the partimage network support, or using Samba / NFS. I am not going to use this feature in this example.


Press F5 to go to the next screen.





Here we can specify the compression level. I am going with the first option i.e. with no compression. If I select None, in that case also only the used blocks will be in the image file. Suppose my partition is 20GB and only 8GB is used, the image file will be around 8GB. Using Gzip and Bzip2 option I can make the file further smaller.
I can use the fsck program to check the partition before creation of the image using the Check partition before saving option.
I can also specify a description of the image, so that in the time of restoration I do not have any confusion in case I have lots of different partition images.
Also I can split the image file into multiple files if my image file is large by specifying the file size. This is especially useful in case I want to write the image files into CD/DVD media.


Press F5 to go to the next screen.


Enter the description of the partition for future reference.



Press OK after entering the description.



Now partimage will check the partition. If it finds any error it will report with a warning message. We can cancel the process here or we can continue with the partition image creation process.






Before starting the partition cloning process partimage will give a summary of the partition.

 Press Enter key to start the partition image creation process.



Partition creation process:
 

After partition image is created, partimage will give the statistical information of the process. Press Enter to exit from partimage.
Restoring Image file

Now I will restore an image file in a different machine. Mount the USB disk which contains the image file into the machine. I have mounted the USB disk in /media/usbdisk folder. I will restore the image file into /dev/hda5 partition which is currently mounted in /data folder.



Start partimage with the command
# partimage

Select hda5 partition (in this partition we will restore the image) in Partition to save/restore.
Enter the name and location of the image file (if we have broken the image files into multiple files like image.000, image.001 etc., then enter only the name of the first image file image.000)
Select Restore partition from an image file in Action to be done

 
Press F5 to go to the next screen.



Always remember to unmount the partition in which we will restore the partition. Otherwise partimage will give the error as shown in the screenshot



Unmount the hda5 partition, also format it to clear all the data in this partition.



After unmounting the partition, start the restoration process again. Select partition, Action to be done and image file and go to the next screen. Partimage will show us the description of the image if we have specified it at the creation of the image file (this will help us to identify the image file properly). If the image is not the correct one, we can exit at this point.

Press Enter to hide the Partition description.


Now we can select some options like simulation of the restoration and erasing free blocks with zero values. Also we can specify what to be done if the restoration is successful.


Press F5 to go to the next screen.


 
Partimage will show the summery of the partition image that we are going to restore.
 
Press Enter to continue.



Now partimage will confirm before starting the restoration process. Press Yes to start restoration process.




Restoration process:

 

After restoration process successfully completed, we will get the statistics of the restoration process.


 Press OK to finish the restoration process.

Its done and that's all for 2day.


জয় আই অসম,
প্রণব শর্মা