Split and Join large files with Linux

Posted by: Mo Mughrabi No Comments »

I've been neglecting this blog for a sometime, the last post from Yousef gave me a nice boost to write something new. Today someone came up to me and asked how can he upload a 3GB file into his remote machine. Well, I will try here to explain how you can split a large file into small parts with the size you want and then how you can join them together again, all using your command line.

To split a file, Let's assume you have a file called TV.SHow.avi (300MB) and you want to split it into 50MB files

 
split -b 50m TV.Show.avi
 

this command by default will generate 6 files with unique naming sequence (e.g xaa, xab, xac..etc) now to join the files you can do

 
cat xaa xab xac xad xae xaf xag > TV.Show.NewFILE.avi
 

or

 
cat x* > TV.Show.NewFILE.avi
 

Searching for text in a collection of files

Posted by: yousef 4 Comments »

I'm pretty sure there are literally tens of (possibly easier) ways to accomplish this, but I've always used the following snippet of bash code to search for text in files (the backslash at the end of the first line indicates continuation and should not be typed in; the two lines below are really one big command, but they are split into two separate lines so it doesn't screw up the page layout on lower resolutions):

for i in *.txt; do echo $i:; cat -n $i | \
grep -i 'search_string'; done

First, "*.txt" is expanded to a list of all files ending in '.txt'. For example, "one.txt two.txt three.txt". Then, $i is set to one of the files (in the order they are listed) at each iteration of the for loop. The commands between the 'do' and 'done' are executed for each file. The name of the current file is printed. Then, the output of `cat -n $i`, which is the contents of file $i (with each line prefixed with the line number), is piped to `grep -i 'search_string'`. This searches for the given text in file $i (ignoring case).

Of course, you can change the above snippet to search for whatever you want, in whatever files you specify. For example, to search for the string 'while' in all C files (.c) in the current directory, change "*.txt" to "*.c" and 'search_string' to 'while'. Or if you want to search in both C files and header files (.h), then use "*.c *.h". You can even use the find utility, as shown here:

for i in `find /some/path -iname "*.html" -print`; \
do echo $i:; cat -n $i | grep -i 'search_string'; done

This is exactly the same as the first command, except "*.txt" was replaced with `find ...`. The back-ticks (`) are substituted with the output of the command they enclose, in this case, the find command. The find command used here prints the absolute paths of all HTML files (i.e. ending in .html) in /some/path, including those in sub-directories, sub-sub-directories, ..etc. These files are then searched for 'search_string'.

Feel free ask questions or post what you personally use when searching for text in files.

Installing tomcat on linux

Posted by: Mo Mughrabi No Comments »

I wish that tomcat can be part of linux installation tools like yum in fedora. I've been struggling for the past 2 hours trying to install the tomcat properly and am not sure its the most proper but for development purposes I think it would be more than enough & since there are very few websites that talk you through the installation process step by step. so, its also a chance to share the experience

First of all, two things you must download before you start with anything
1. JDK (Java development kit) from sun website.
2. Then you will have to download the tomcat at apache website.

The second step, is to extract the JDK, either it is tar file or rpm files it will into a directory where ever you place it (we will assume this path /home/mo/jdk/).

Finally is to extract the tomcat files (if we assume that you extracted under /home/mo/tomcat/) then you must setup the java home directory

export JAVA_HOME='/home/mo/jdk/'

then you must setup the home directory for the tomcat as following

export CATALINA_HOME='/home/mo/tomcat/'

Now, you must do this step

cd $CATALINA_HOME/bin
    tar xvfz jsvc.tar.gz
    cd jsvc-src
    autoconf
    ./configure
    make
    cp jsvc ..
    cd ..

then open your browser and access your tomcat and see, by default it is set on port 8080. so, you must enter the URL as following

http://localhost:8080/

source

وفاة الشيخ الأمير الوالد سعد العبدلله الصباح اليوم

Posted by: Mo Mughrabi 2 Comments »

الشيخ سعد

{ يا ايتها النفس المطمئنه ارجعي الى ربك راضية مرضيه فادخلي في عبادي وادخلي جنتي } صدق الله العظيم
انتقل الى رحمة الله تعالى الشيخ الأمير الوالد سعد العبدلله السالم الصباح اليوم
داعين الله عز وجل أن يتغمد الفقيد بواسع رحمته ويسكنه فسيح جناته

Blood bank in Urood

Posted by: Mo Mughrabi No Comments »

Yesterday Urood team started something extremely useful here in Kuwait. Its not just a brilliant idea but its truly creative and it came when most needed. Ever now and then I see posts and ads about blood donations and how it may save lives! Urood came up with a new section "Community service" part of the community service is the blood bank link.

All you have to do is, click on the link and type write your information and blood type. so, if someone is in emergency they can look up matches on Urood. I think, this is wonderful and everyone should participate in this great humanitarian service

click here to start input or searching for a match
or just click here to view Urood home page

Have a great day every one,

Creating web interface to access your remote Linux servers

Posted by: Mo Mughrabi No Comments »

Its been a while since last I've posted anything but am here trying to keep up with many websites. Any who, Recently I was requested by one of my clients to create a web interface to help the none technical restart apache, mysql and do some monitoring on different servers.

so, first what I did is generate a key to create secure channels between the servers in order to connect without prompting for password (click here for steps). Then, I faced some trouble writing the PHP code which will connect and do these tasks and after long day of surfing and some help from my team (Basant) we finally nailed it.

First, you will need to install openssl (openssl-devel), then download and compile libssh2 and then you will need to add the extension in your PHP.ini (click here for PHP ssh2 installation manual) and here is a sample code on how it can be done in PHP.

  1.  
  2.  
  3. // Notify user if the server terminates the connection
  4. function my_ssh_disconnect($reason, $message, $language)
  5. {
  6. printf("Server disconnected with reason code[%d] and
  7. message: %s\n" ,$reason, $message);
  8. }
  9.  
  10. $methods = array(
  11. 'kex' => 'diffie-hellman-group1-sha1',
  12. 'client_to_server' => array(
  13. 'crypt' => '3des-cbc',
  14. 'comp' => 'none'),
  15. 'server_to_client' => array(
  16. 'crypt' => 'aes256-cbc,aes192-cbc,aes128-cbc',
  17. 'comp' => 'none'));
  18.  
  19. $callbacks = array('disconnect' => 'my_ssh_disconnect');
  20.  
  21. $connection = ssh2_connect('domain_name.com', 22, $methods,
  22. $callbacks) or die('Couldnot locate the ssh2');
  23. if (!$connection) die('Connection failed');
  24. if (ssh2_auth_password($connection, 'linux_user',
  25. 'linux_password')) {
  26. echo "Authentication Successful!\n\n";
  27. $shell=ssh2_shell($connection, 'bash') or die("error");
  28. // fwrite will send execute commands and return value in
  29. $shell
  30. fwrite( $shell, "/etc/init.d/httpd restart\n");
  31.  
  32. // this will look the $shell array and print the
  33. returned value.
  34. while($line = fgets($shell)) {
  35. flush();
  36. echo $line."";
  37. }
  38.  
  39. fclose($shell); // close connection
  40. }else{
  41. echo "Error with connection\n";
  42. }
  43.  
  44. ?>

KwtLinux on facebook

Posted by: Mo Mughrabi No Comments »

I just finished creating KwtLinux group on facebook as its will help in spreading the word. Specially that facebook has become one of the largest communities packed with users from Kuwait, If you are a facebook member you can go ahead and join us here.

Mounting remote folder (Fedora)

Posted by: Mo Mughrabi No Comments »

If you are working with servers, you probably came through this issue before. Let's say you have two servers and you need to setup an automated backup or you want to share files from different server yet you want to save time writing scripts to pull the files or push the backup through FTP. Mounting a remote folder will save you lots of time since the mounted folder will act like a local folder and all you have to do is move or copy your files to the local path and its will be placed on the remote server. so, its useful for many uses and here is the steps on how to set it up on a linux fedora.

First, you will need to install the required package

 
yum install fuse
yum install fuse-sshfs

Then, grant the user access to the fuse group

 
usermod -G fuse linuxuser <em>Replace linux user with your linux user</em>
 

Now, you are ready to issue the command which will mount the remote folder on your current system.

 
sshfs -o nonempty 192.0.0.1:/remote_folder/full/path /local_folder/full/path
 

Where nonempty means that the remote folder is not empty
192.0.0.1 is the remote server IP address (local network or over the internet)
/remote_folder/full/path is the full path for the remote folder
/local_folder/full/path is the full path for the local folder to mount on (folder should be created first)

Put on your questions in the comment section if you have any & hope have fun networking,
Have a good day all,

Update: If you wish to unmount the folder you can use the following command

 
fusermount -u /local_folder/full/path
 

Alienware, Power your linux

Posted by: Mo Mughrabi No Comments »

Alienware Area-51 7500
Recently I've been looking up desktop's to use with Linux & for gaming purposes. & I came across Alienware which is extremely powerful for personal desktops, as I wondered around reading about Alienware I came to know that they been around for sometime now. Most review shows that people are highly satisfied with Alienware performance specially with Ubuntu graphical interface & since most Alienware running at least a NVIDIA® SLI™ Dual Graphics which makes the Ubuntu experience superb.

Alienware desktops starts at 1,199$ with the Area-51 7500 & can goes up till 5,149$ with the Area-51 ALX Crossfire. Also it comes with Windows Vista of your choice & can easily be replaced with your favorite linux distribution off course. You can see a list of all the Alienware desktops here or list of the laptops here.

Hacking PDF Passwords with Ubuntu

Posted by: Soul 6 Comments »

You guys might have encountered PDF files with password protection sometime or the other.

Its easier to hack those password protected files now with UBuntu.

You wouldnt be needing those KD sucking software anymore.

Go to console/terminal, type the following code.

$ pdftops protected.pdf out.ps
$ pstopdf out.ps out.pdf

Where,

protected.pdf is the protected PDF file

out.ps is an intermediate output of the protected PDF file

out.pdf is the final cracked PDF file

Thats it for the day. More hacks to come.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Login