Thursday, April 13, 2017
XScreenSaver
See: https://www.jwz.org/xscreensaver/
This is a very nice introduction to Writing an Xscreensaver Module using Xlib.
Wednesday, September 9, 2015
Saturday, September 5, 2015
Find linux distro
a) /etc/*-release file. (for distro, may include multiple release files under /etc/)
b) /proc/version file. (for linux version)
c) lsb_release command. (for hardware version)
See http://www.cyberciti.biz/faq/find-linux-distribution-name-version-number/
Thursday, August 27, 2015
Share a folder between windows and linux
To share a windows folder with linux, you can use cifs-utils. Details are below:
1) Create windows shared folder [2] on windows machine (say MachineX): C:\Shared\
- now can access \\MachineX\Shared\ on other machines on the same domain.
2) Download/Install cifs-utils on linux machine:
- download from [3].
- unzip and install:
bzip2 -d cifs-utils-6.4.tar.bz2
tar xvf cifs-utils-6.4.tar
cd cifs-utils-6.4
./configure --prefix=/usr \
--disable-pam \
--disable-systemd
make
sudo make install
- finally, the command is available on linux by: sudo /sbin/mount.cifs
3) Mount the shared folder on linux:
- mount:
cd /mnt
sudo mkdir MachineX_Shared
sudo /sbin/mount.cifs //[MachineX IP address]/Shared /mnt/MachineX_Shared -o user=[username]
- now can access the folder and write to it.
References:
[1] http://www.howtogeek.com/176471/how-to-share-files-between-windows-and-linux/
[2] http://lifehacker.com/288033/mount-a-windows-shared-folder-in-linux
[3] http://www.linuxfromscratch.org/blfs/view/svn/basicnet/cifsutils.html
Monday, March 16, 2015
Monitor Linux (Ubuntu) network traffic in real time
[http://manpages.ubuntu.com/manpages/lucid/man1/tcptrack.1.html]
ifstat
iftop
iptraf
tcptrack
== Commands to verify ports:
[https://www.serverpronto.com/accounts/knowledgebase.php?action=displayarticle&id=11]
nmap IP#
nmap localhost
netstat –ntulp
== to verify single port
netstat -nap | grep
== to list all current rules in iptables
iptables -L
== For opening a TCP port:
iptables -A INPUT -p tcp –dport
== For opening a UDP port:
iptables -A INPUT -p udp –sport
== Save changes:
iptables-save > /etc/iptables.rules
== If you need to disable the firewall temporarily, you can flush all the rules using:
iptables -F
Thursday, August 21, 2014
Count LOC recursively
find . -name '*.java' | xargs wc -l
See [1].
[1] How to count all the lines of code in a directory recursively?
Tuesday, March 11, 2014
Protect unix/linux directory using .htaccess and .htpasswd
The article below is copied from [1].
References:
[1] HTPassword Tutorial
[2] Password Protection with .htaccess & .htpasswd
[3] Apache HTTP Server Tutorial: .htaccess files
Password Tutorial
If you would like to have a set of web pages that are protected, requiring a username/password to gain access, this tutorial will show you how to set it up. This is geared towards the Unix Apache httpd servers used on holly, lamar, and www.colostate.edu. If you are using another web server, you'll need to check that server's documentation to see how to do this.Steps to Password-protect a Directory
First, create a subdirectory in your web area. For the sake of this tutorial, I have created the "protect" directory. Set the permissions on the directory so that the server has read/execute. I do this by using the local command chgrp-www to set the group to the www group. This is the group that the server runs under at Colorado State University for the lamar, holly and www servers. I have used the -sd flag which sets "set group id" for a directory. This will then force any files you create within the protect directory to the www group, so if you ftp files to this directory they will be automatically readable by the server but not by any other user on the system. I then cd into the protect directory.Next you must create a .htaccess file inside the directory you want protected. You can use either the vi or pico editors on the supported systems mentioned above or ftp the file to this directory. If you are new to unix or know little about vi then I suggest you use the pico editor or ftp the .htaccess file. The command to edit with pico is "pico .htaccess". The .htaccess file should contain the following lines. The items in bold are things you will want to change depending on the location of the AuthUserFile and content of AuthName.cd ~ric/public_html mkdir protect chmod g+r,g+x,o-r,o-x protect chgrp-www -sd protect cd protect
The AuthName is what the user will see when they're prompted for a password - something to the effect of "Enter the username for Ric's Protected files". The AuthUserFile is location of the password file and should be not accessible with a url on the server for security reasons. This is a full unix path and the permissions should be set up like the "protect" directory using the chmod and chgrp-www commands above so the only one that can read this file is the owner and the server. To get the full path of a directory, cd to that directory and enter the command "pwd" to print the working directory path. Now you'll have to set up the password file. You'll need to use the htpasswd program. It is included with the Apache httpd server.AuthUserFile /z/ric/secret/.htpasswd AuthGroupFile /dev/null AuthName "Ric's protected files" AuthType Basic<Limit GET > require valid-user </Limit>
First cd to the directory that contains the password file. In this example the password file is called .htpasswd and is in the directory /z/ric/secret/ as indicated by the AuthUserFile file entry in the .htaccess file. For every username you want to add to the password file, enter the following. (the -c is only required the first time; it indicates that you want to create the .htpasswd file).
cd
mkdir secret
cd secret
htpasswd -c .htpasswd pumpkin
[ you're prompted for the password for pumpkin]
[ if you have other users enter the following. Don't use the -c]
htpasswd .htpasswd user2
htpasswd .htpasswd user3
Again, make sure the permissions are set up like the "protect" directory
using the chmod and chgrp-www commands above so the only one that can
read files in the "secret" directory is the owner and the server.
Here is the protected page using the above
setup to password protect this page. The username is "pumpkin" and
password is "pie".
Monday, February 3, 2014
Saturday, March 23, 2013
Monitor url content
then
sendmail -t <
To: to@email.com
Subject: your key word appeared
in URL
FOO
fi
Add this script to crontab.
Wednesday, July 27, 2011
find command batch processing
find -iwholename './*.svn' -exec rm -Rf '{}' \;
Monday, December 13, 2010
Setup email forwarding in linux/unix
Under linux/unix, it can done by admin or by user himself, as explained here.
To do it by the user himself, he only needs to create a file .forward in his account root, and enter the forward email addresses separated by comma or new line. The .forward file should have permission 644.
An example .forward file is:
"|/usr/local/bin/procmail"
example@gmail.com
Tuesday, March 30, 2010
awk, uniq, tr and grep
Remove duplicate lines with uniq
A user's guide for GNU AWK
AWK one-liners
AWK can process each line of a file and gives relevant output.
One problem is to find the number of occurrences of a word in a file. It's easy to output the lines that contain such a word, or count the number of such lines. But if a line contains multiple occurrences of a word, the solution is not so easy. One solution is to use the "tr" command to break the fields in a line to one word each line, and then employ common approach.
grep can be used to find a word in files. The following recursively find in current directory and sub-directories for files that contain "word":
grep -R "word" *
Wednesday, October 28, 2009
Linux admin notes
- Install software on Unix/Linux
- ./configure, make, su, make install
- Redhat: rpm. Debian: apt-get. Mandrake: urpm. Fedora: yum. Slackware: . Gentoo: Emerge.
- Install binary (.BIN, .SH):
- Install package:
Thursday, June 19, 2008
Setup Suse 10.3 & Linux notes
Download Open Suse: http://en.opensuse.org and see http://en.opensuse.org/Download_Help
Summary - These tools were configured to use:
- Apache 2.2 web server
- Bison 2.3
- Flex 2.5.33
- Ftp server
- Gcc 4.2.1 (C/C++)
- Java 1.5.0
- Mono (C# cross compiler)
- MySQL (Ver 14.12 Distrib 5.0.45, for suse-linux-gnu (i686) using readline 5.2)
- Perl (v5.8.8 built for i586-linux-thread-multi)
- Php (PHP 5.2.4 with Suhosin-Patch 0.9.6.2 (cli) (built: Sep 23 2007 14:12:53))
- phpBB 3.0.1
- Python 2.5.1
- SSH server
Demos
- cgi-bin/hi.cgi (cgi written in Perl)
- cgi-bin/hi.pl (cgi written in Perl)
- cgi-bin/chi.cgi (cgi written in C)
- php/index.php (PHP)
- cgi-python/hi.py?user_name=me
(Python as cgi, use mod_python.cgihandler as handler) - python/index.py (with a function hello(req, who))
(Python, use mod_python.publisher as handler, the better way) - Perl using MySQL database
Apache
- www root is /srv/www/htdocs/
- config files are in /etc/apache2/
- See apache.txt for configuration change.
Crontab
MySQL- Install notes
- See Setup guide
- The Perl-DBD-MySQL module was missing. So download and install using YaST.
- DBD::mysql module note
- DBD modules download
- Database auto-backup using crontab
Menhir
- Menhir install records
OCaml
phpBB
- phpBB website
- To install is very easy, follow the instruction guide. Note that the database needs to be created manually.
(For MySQL, in MySQL shell, type "create DATABASE [database_name]")
Python
Ruby on Rails
General note
- Notes on install CPAN modules
- Installing Perl Modules
- In Suse, can use YaST --> Software Management to install new package.
- More notes
=hi.cgi=#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
print "<html><head><title>Hello World! </title></head>\n";
print "<body><h1>Hello world! From Perl CGI</h1></body></html>\n";
=hi.pl=
#!/usr/bin/perl
#use CGI qw(:standard);
#use DBI;
#use strict;
#print header;
#print end_html;
print "Content-type: text/html\n\n";
print "<html><head><title>Hello World! </title></head>\n";
print "<body><h1>Hello world! From public_html/cgi-bin/</h1></body></html>\n";
=chi.cgi=
#include <stdio.h>
int main() {
printf("Content-type: text/html\n\n");
printf("hello world from C\n");
return 0;
}
=index.php=
<?php echo "hello world from php!<br/>"; ?>
<?php phpinfo(); ?>
</p>
#!/usr/bin/python
import cgitb; cgitb.enable() # provides HTML error support
import cgi
form = cgi.FieldStorage()
def CGI(content_type = "text/html"):
return 'Content-type: %s\n\n' % content_type
def form_value(key):
"""
Use this simple method to get http POST's
"""
val = form.getlist(key)
if (val == None): return None
return val
user_name = form_value('user_name')
def display_page(name):
print CGI()
print "<html><head><title>"\
"This is %s's page</title>"\
"</head><body><h1>Welcome, %s"\
"</h1><body></html>" %(name, name)
return 1 #
display_page(user_name)
=index.py=
# This is useless
#def html_header(content_type = "text/html"):
# return 'Content-type: %s\n\n' % content_type
def hello(req, who="nobody"):
val = "<html><body><h1>Hello, %s</h1></body></html>" % who;
return val
=everest.pl=
#!/usr/bin/perl -w
use CGI qw(:standard);
use DBI;
use strict;
print header;
#print start_html("Test MySQL Database");
print "<html>\n<head><title>Test MySQL Database</title>\n";
print "<link href="'../everest.css'" rel="'stylesheet'" type="'text/css'">\n";
print "</head>\n<body>\n";
print "<h1>Test MySQL Database</h1><br />\n";
my $dbh;
db_connect();
if (not $dbh) {
print "cannot open databse<br />\n" . DBI::errstr;
exit(0);
}
#print "Database opened<br />\n";
# prepare and execute query
my $sort = param("sort");
my $orderby = param("orderby");
get_sortinfo();
my $query = "SELECT * FROM tblEverest ORDER BY $orderby $sort";
#print $query . "<br />";
my $sth = $dbh->prepare($query);
$sth->execute;
# assign fields to variables
my ($id, $pdate, $pname, $pdesc);
$sth->bind_columns(\$id, \$pdate, \$pname, \$pdesc);
print "rows = " . $sth->rows() . "<br />\n";
# output name list to the browser
print "Data in the tblEverest table:<p>\n";
print "<table class="'dataTbl'">\n";
print "<tr class="'dataTitle'">\n" .
"<td width="50"><a href="'?orderby="id&sort="$sort'">ID</a></td>\n" .
"<td><a href="'?orderby="date&sort="$sort'">Insertion Date</a></td>\n" .
"<td><a href="'?orderby="name&sort="$sort'">Protein name</a></td>\n" .
"<td><a href="'?orderby="desc&sort="$sort'">Description</a></td>\n" .
"</tr>\n";
while($sth->fetch()) {
print "<tr><td>$id</td>";
print "<td>$pdate</td>";
print "<td>$pname</td><td>$pdesc</td></tr>\n";
}
print "</table>\n";
$sth->finish();
# disconnect from database
$dbh->disconnect;
print end_html;
1;
sub get_sortinfo {
if ($orderby eq "" or $orderby eq "id") { $orderby = "tblEverestID"; }
elsif ($orderby eq "date") { $orderby = "InsertDate"; }
elsif ($orderby eq "name") { $orderby = "Name"; }
elsif ($orderby eq "desc") { $orderby = "Description"; }
if ($sort eq "DESC" or $sort eq "") { $sort = "ASC"; }
else { $sort = "DESC"; }
}
sub db_connect() {
my ($db, $host, $userid, $passwd, $connectionInfo);
#database information
$db="dbname";
$host="localhost";
$userid="uid"; # check mysql.user for valid user.
$passwd="pwd";
$connectionInfo="DBI:mysql:$db;$host";
# make connection to database
$dbh = DBI->connect($connectionInfo,$userid,$passwd);
}
=apache.txt=
http://bozziesfw.wordpress.com/2007/02/24/configuring-apache-using-yast-opensuse-102/
Try this, configure apache2 using YaST.
The apache's www folder is in /srv/www/htdocs/
The index.html file for "It works!" is there.
Add this to /etc/apache2/mod_userdir.conf:
<Directory /home/*/public_html/cgi-bin>
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
#SetHandler cgi-script
AddHandler cgi-script .cgi .plx .pp
Order allow,deny
Allow from all
</Directory>
Then restart the httpd server using: /etc/init.d/apache2 force-reload
Then it's ok.
--
php already works by default.
--
Added these to /etc/apache2/mod_userdir.conf:
<Directory /home/*/public_html/python>
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
<Directory /home/*/public_html/cgi-python>
AddHandler mod_python .py
PythonHandler mod_python.cgihandler
PythonDebug On
</Directory>
Now python works:
# cgi-python/hi.py?user_name=me
(Python as cgi, use mod_python.cgihandler as handler)
# python/index.py (with a function hello(req, who))
(Python, use mod_python.publisher as handler, the better way)
=crontab.txt=
crontab -e : edit the crontab file for the current user.
The result is stored one entry for each user in /var/spool/cron/tabs/.
In /etc/ there are these files:
cron.deny, crontab, cron.d, cron.daily, cron.hourly, cron.monthly, cron.weekly.
I have created a cron job to back up wikidb database. The script is:
/srv/www/htdocs/wiki/database_bck/autobackup
Then use "/etc/init.d/cron restart" to restart the cron daemon.
=Mysql install note=
MySQL
Setup: http://vias.org/linux-knowhow/lnag_09_06.html
Suse-Everest:/etc # /usr/bin/mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h host.dummy.edu password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
Suse-Everest:/etc # chown -R mysql /var/lib/mysql
Suse-Everest:/etc # chgrp -R mysql /var/lib/mysql
Suse-Everest:/etc # /usr/share/mysql/mysql.server start
Suse-Everest:/etc # mysqladmin --user=root password '********'
=ocaml.txt=
Download from:
http://caml.inria.fr/download.en.html
http://caml.inria.fr/pub/distrib/ocaml-3.10/ocaml-3.10.2.tar.gz
Copy ocaml-3.10.2.tar.gz to /usr/local/src/, unzip it.
Then read README, then read INSTALL and follow the instruction in it.
--
Objective Caml system has these commands:
ocamlc the batch bytecode compiler
ocamlopt the batch native-code compiler (if supported)
ocamlrun the runtime system for the bytecode compiler
ocamlyacc the parser generator
ocamllex the lexer generator
ocaml the interactive, toplevel-based system
ocamlmktop a tool to make toplevel systems that integrate
user-defined C primitives and Caml code
ocamldebug the source-level replay debugger
ocamldep generator of "make" dependencies for Caml sources
ocamldoc documentation generator
ocamlprof execution count profiler
ocamlcp the bytecode compiler in profiling mode
and also, if you built them during step 5, [yes I did]
ocamlc.opt the batch bytecode compiler compiled with ocamlopt
ocamlopt.opt the batch native-code compiler compiled with ocamlopt
ocamllex.opt the lexer generator compiled with ocamlopt
=More notes=
- switch b/w GUI and command line:
press Ctrl+Alt+F2 to leave the graphical user interface.
If you want to go back to the graphical user interface you
should log out from your shell session first. To do so, type
exit and press Enter. Then press Alt+F7 to switch back to the
graphical user interface.
When you are already logged in to the GNOME or the KDE desktop
and want to start a terminal window within the desktop, press
Alt+F2 and enter konsole (for KDE) or gnome-terminal (for GNOME).
To close the terminal window press Alt+F4.
- Bash shortcut keys
http://linuxhelp.blogspot.com/2005/08/bash-shell-shortcuts.html
- Exmaples.
sudo chown wilber kde_quick.xml
History: You can also search for a certain command in the history.
Press Ctrl+R to start an incremental search function.
Completion: Completing a filename or directory name to its full
length after typing its first letters is another helpful
feature of Bash. To do so, type the first letters then
Browse in the history of executed commands:
press Tab (Tabulator).
8.8 Searching for Files or Contents: locate, find, grep.
locate .gnome
find ~ -name *.txt
grep "music is great" ~*.*
8.10 Redirection and pipe:
ls -l >> filelist.txt
ls -l | grep tux
8.11 Handling Processes
Press Ctrl+Z to suspend the process and enter bg to send
the process to the background.
Sending a process to the background directly when starting
it. To do so, add an ampersand at the end of the command.
-jobs-
Whereas job only shows the background processes started from
a specific shell, the ps command (run without options) shows
a list of all your processes—those you started.
To bring a job to the foreground again, enter fg job number.
Use the kill command to stop a process. This sends a TERM signal
that instructs the program to shut itself down.
e.g., kill 30187
// Alternatively, if the program or process you want to terminate
is a background job and is shown by the jobs command, you can also
use the kill command in combination with the job number to
terminate this process:
kill % job number
kill -9 PID // This sends a KILL signal instead of a TERM signal,
bringing the specified process to an end in most cases.
* Show IP: /sbin/ifconfig
* Configure network card for LAN and Internet access: http://www.swerdna.net.au/linhowtonic.html
* Remote admin: http://en.opensuse.org/YaST_Remote_Administration
* VNC (http://www.realvnc.com/):
192.168.100.1:5900 Use F8 to get menu in full screen mode.
* Setting bash: http://tldp.org/LDP/abs/html/sample-bashrc.html
* Reboot: reboot
* Now sshd and apache2 can automatically start at boot time.
* Enable mysql auto start at boot time: Copy "/usr/share/mysql/mysql.server start" to the end of /etc/init.d/rc
* Configure apache2: /etc/apache2/httpd.conf Add "/etc/apache2/httpd.conf.local" to to value of APACHE_CONF_INCLUDE_FILES in /etc/sysconfig/apache2
* Restart apache2: /etc/init.d/apache2 restart
* Apache: http://httpd.apache.org/
* umask 022: umask 022 - Assigns permissions so that only you have read/write access for files, and read/write/search for directories you own. See http://linuxzoo.net/page/sec_umask.html
* crontab
* Show CPU and Memory information:
cat /proc/cpuinfo, cat /proc/meminfo
Blog Archive
-
▼
2026
(36)
-
▼
June
(19)
- C10K to C10M: from thread-per-connection model to ...
- Benchmark server performance
- Application server for php, python, java, node.js,...
- Application server for C++, Go and Rust
- Nginx as reverse proxy and load balancer
- Infrastructure running: nginx, apache, php, python...
- Flow chart of nginx+apache+uvcorn infrastructure
- Flow chart of apache+uvcorn infrastructure
- Uvicorn and Gunicorn
- What's deadsnakes PPA
- What's the optional lsb-core package
- Codex known logging bug
- Daemonsize a service
- Train text to image model, to generate images of c...
- Train a model based on OpenAI API
- Open port 8080 for WebSocket
- Add websocket support on Bluehost Ubuntu VPS for D...
- Install Claude Code on ubuntu VPS of Bluehost
- Install PostgreSQL on Mac
-
▼
June
(19)