Record Terminal session as text

I have gone through some wonderful command today named as script. You know what it do , it will simply record all your terminal sessions as text.

Usage : script <filename>

Example:

Screenshot - Monday 04 May 2015 - 06:22:01  IST

In the example you can see, after I typed as script terminal01 , its started storing all the text I am typing after it and its stopped doing that after I have typed exit.

I have seen the same what I have typed in the terminal with more terminal01 command. you can see it in the image.

Hope that helps.

Advertisements

Strange Python — Command Line Arguments

When I am doing little bit mess around with Python , I’ve gone through command-line arguments.

So , Lets start!!!

Actually Command line arguments are pretty familiar things to us if we have programming knowledge , doesnt matter what language it is.

These Command line arguments are not preloaded with default python modules, you have to load a module named as “sys” module and then only we will able to use command line arguments.

lets start with a small program!!

raja@raja:~/python$ cat carg1.py
#!/usr/bin/python

import sys

def carg1():
print sys.argv[1]
if __name__  ==  ‘__main__’:
carg1()

raja@raja:~/python$

So as I told you , to use command line arguments in python we need to import sys module and we are doing that with import sys.

Then I am writing a small python function and calling it.

so remember when ever we are executing these command line argument type programs we must pass arguments while executing the program , if we dont then we will get error like below

raja@raja:~/python$ python carg1.py
Traceback (most recent call last):
File “carg1.py”, line 10, in <module>
carg1()
File “carg1.py”, line 6, in carg1
print sys.argv[1]
IndexError: list index out of range
raja@raja:~/python$

So we must pass the argument ,while running script

raja@raja:~/python$ python carg1.py raja
raja
raja@raja:~/python$

So above scripts seems to all good, what the strange thing with Python – Command Line arguments ?

Lets see a small addition program!!!

raja@raja:~/python$ cat addfarg.py
#!/usr/bin/python
import sys
def addfun(a,b):

su = a + b;
print su

if __name__ == ‘__main__’:
addfun(sys.argv[1],sys.argv[2])

raja@raja:~/python$

and when I tried to execute that program

raja@raja:~/python$ python addfarg.py 12 14
1214
raja@raja:~/python$

but it supposed to print 26 , so whats going wrong ?

I think may be Python received command line argument as string not as its original data type.

So what I am supposed to do ?

I have to convert these command line arguments as integers before I add them.

#!/usr/bin/python
import sys
def addfun(a,b):
a = int(a)
b = int(b)
su = a + b;
print su

if __name__ == ‘__main__’:
addfun(sys.argv[1],sys.argv[2])

we can do this program little bit shorter but not complex.

#!/usr/bin/python
import sys
def addfun(a,b):
su = int(a)+int(b)
print su

if __name__ == ‘__main__’:
addfun(sys.argv[1],sys.argv[2])

So the strange I noticed with Command Line argument is that but actually its not strange at all. If you remember java command line arguments the answer is with you already else just google.
That’s it.

Working with Apache2 -VirtualHosts in Ubuntu

Here my intention is very clear that I need a mylocal web saltstake documentation so when ever I want to read I can read that doesnt matter of internet connection.

By the way official PDF,epub documentation is available.

1. Chosen some hostname for example mysaltstack.com and same with www. add these names with IP you want with localhost in /etc/hosts file.

echo “127.0.0.1 mysaltstacke.com” >> /etc/hosts
echo “127.0.0.1 mysaltstacke.com” >> /etc/hosts

2 So next placed particular website content in /var/www/html/ folder and then changed permission to raja.

cd /var/www/html/
chown -R raja.raja SalkStaka/

and now checking

root@raja:/var/www/html# ls -ltrh
total 20K
-rw-r–r– 1 root root 12K Jan 12 20:35 index.html
drwxr-xr-x 9 raja raja 4.0K Jan 12 21:30 LPIH
drwxrwxr-x 3 raja raja 4.0K Mar 27 14:17 SaltStake

3.Now location set , site name set. We have to focus on remaining configuration of the website.
First lets focus on sites-available/ directory. Here we write configuration for available sites. so copy existing configuration and name it into our new site then we can do changes internally.

cp /etc/apache2/sites-available/mypython.com.conf /etc/apache2/sites-available/mysaltstake.com.conf

edit the file with

vim /etc/apache2/sites-available/mysaltstake.com.conf

Then add/modify following lines accordingly

ServerAdmin raja@localhost
DocumentRoot /var/www/html/SaltStake
ServerName mysaltstake.com
ServerAlias http://www.mysaltstake.com
DirectoryIndex contents.html

Then save & Close.

4. So after we did this we have to enable to site , when we enabled automatically it will sync with sites-enabled directory.

To enable a site

a2ensite mysaltstake.com

then after that if you look into sites-enabled

root@raja:/etc/apache2# ls -ltrh /etc/apache2/sites-enabled/
total 0
lrwxrwxrwx 1 root root 35 Jan 12 20:35 000-default.conf -> ../sites-available/000-default.conf
lrwxrwxrwx 1 root root 35 Jan 12 21:16 example.com.conf -> ../sites-available/example.com.conf
lrwxrwxrwx 1 root root 32 Jan 12 21:16 test.com.conf -> ../sites-available/test.com.conf
lrwxrwxrwx 1 root root 36 Jan 12 21:26 mypython.com.conf -> ../sites-available/mypython.com.conf
lrwxrwxrwx 1 root root 39 Mar 29 12:43 mysaltstake.com.conf -> ../sites-available/mysaltstake.com.conf

a link created between available-sites and enabled-sites.

then restart/reload apache2 with

service apache2 reload

That’s it.

It will work for VirtualHosting with IP and name

SaltStack Configuration Management tool.

Hello Readers,

It been a very long time that I had posted something. I want to share good news that I have got job so become busy these days. Its not a technical post but personal one.

So I want to learn something new , something different but helpful in future. Eyes looked on so many things but stopped at Configuration Management tools. As I have a very old laptop , I can practice and post very few tools and in that I mounted on SaltStack CM tool.

So In future I will try to post minimum weekly one post on SaltStack CM tool.

So wish me best and have a good time.

Regards

Raja