Introduction to Unix, SGE, Emacs and ROOT (06/03/2010)

Report
Introduction to
Unix, SGE, Emacs & ROOT
Jianchun Wang
06/03/2010
Files for Reference
cp –r ~jwang/For_Group ~/UnixTest
.login
.tcshrc
login startup file
shell startup file
.Xdefaults
default X parameters by “xrdb –merge .Xdefaults”
.emacs
setup emacs environment
config
configure certain ssh settings
sample.job
SGE batch job sample script
hp1.root
example.C
for ROOT demonstration
06/03/10
Jianchun Wang
2
Linux Cluster
GigaBit local net
public net
New disk server
16 TB (max 48 TB)
hepc1, hepc2: dual CPU
2GB RAM, 150GB disk
Gate way, SGE master,
LHCb library service
/home disk
06/03/10
node1-15: single CPU,
1GB RAM, 160 GB disk
Disk server, dual CPU,
2GB RAM, 2.7 TB RAID
Provide data storage
Run background jobs
/tmp storage
Jianchun Wang
3
Unix Account
 Identity of your account:
home directory, shell
username, password, UID, GID, full name,
13:[email protected] ypcat passwd | grep jwang
jwang:$1$P8CxmAXK$.dRGuAxw6Y2vFsnyIImjB/:272:551:Jianchun Wang:/home/jwang:/bin/tcsh
 Login and logout




Use hummingbird exceed
ssh hepc1 –l jwang
exit, logout
sftp, scp
 Setting password:
passwd, yppasswd
 Shells:
tcsh (recommended), bash, csh, …
06/03/10
Jianchun Wang
4
Unix Shells
 A shell is the interface between the OS and the user. It interprets the
commands you enter to direct the OS to take an appropriate action.
 Two families of shell.
 Based on the Bourne shell: sh, ksh, bash, zsh.
 Based on the Berkeley/C shell: csh, tcsh.
 To show what shell you are using: in passwd file, finger, echo $SHELL, env,
printenv.
 You are using either tcsh or bash as login shell. To change to other
shell temporarily, type the shell as a command. Once you are done,
type “exit” to quit the temporary shell.
06/03/10
Jianchun Wang
5
Basics on Command
 Command prompt: %, $, or whatever prompt you set, e.g. 9:[email protected]
for me.
 Basic format: command [-option(s)] [argument(s)]
 date -u
 gcc –o outputfile.o yourprogram.C
 Help on command: man.
 Search path: PATH is defined in your startup files. Mine is defined in
.tcshrc file.
10:[email protected] echo $PATH
/home/sge/root/bin/lx24x86:/lhcb/lib/lhcb/LBSCRIPTS/LBSCRIPTS_v5r1/InstallArea/scripts:/lhcb/lib/lhcb/C
OMPAT/COMPAT_v1r5/CompatSys/slc4_ia32_gcc34/bin:/lhcb/lib/lcg/external/Python/2.5.4p2/slc4_ia32_gc
c34/bin:/lhcb/lib/contrib/CMT/v1r20p20090520/Linuxi686:/home/jwang/bin:/usr/sue/bin:/bin:/usr/local/bin:/usr
/bin:/usr/bin/X11:/cern/pro/bin:/usr/kerberos/bin:/cern/pro/bin:/lhcb/lib/lcg/external/ROOT/pro/slc4_ia32_gcc
34/root/bin
 Start background process:
06/03/10
xterm &
Jianchun Wang
6
Input/output of Command
 The shell and many commands take input from standard input (stdin),
normally keyboard. And They write out to standard output (stdout), and
error output to standard error (stderr), normally the terminal screen.
 Redirection of stdin, stdout, stderr:
>
>&
<
|
>>
redirect stdout >! overwrite if you set protection (set noclobber)
redirect stdout, stderr
redirect stdin
redirect stdout to another command (pipe)
append stdout
 Examples:
 ls –l ~ | sort –k 5 > /tmp/filelist
 (date; echo $USER) >> ~/logfile
 grep –i set ~/.tcshrc | tee set_list | sort
06/03/10
Jianchun Wang
7
Shell Script and Profile Files
 A shell script is a file containing a sequence of commands which
can be executed by the shell.
 . scriptfile
( Bourne shell family)
 source script_file
( C shell family)
 scriptfile
( executed as a command, must be executable)
 User-specified startup files
 tcsh:
 bash:
.login,
(all in $HOME directory).
.tcshrc or .cshrc,
.bash_profile or .profile,
.logout.
.bashrc,
.bash_logout.
 There are also system startup files. They are different for
different computers setting by system administrator.
06/03/10
Jianchun Wang
8
Environment Variables
 Setting environment variables:
 setenv ROOTSYS /lhcb/lib/lcg/external/ROOT/pro/slc4_ia32_gcc34/root
(tcsh)
 ROOTSYS= /lhcb/lib/lcg/external/ROOT/pro/slc4_ia32_gcc34/root;
export ROOTSYS (bash)
 printenv, env, echo $PWD
 Changing command prompt:
 PS1=“Hello:”
(Bourne shell family)
 set prompt=“$cwd” (C shell family)
 set prompt="%U%T@%m%u "
11:[email protected] (mine)
 Some useful environment variables:
EDITOR, PRINTER, MAIL, HOME, PWD, PATH, MANPATH,
DISPLAY, TERM, HOST, SHELL, USER, …
06/03/10
Jianchun Wang
9
Command Alias and Recall
 Format of the alias command




alias new old
alias –x new=old
alias new=old
alias new old
(C shell)
(Korn shell)
(bash, zsh shell)
(tcsh shell)
 Recalling command: history






set history = 100 (tcsh shell)
history
give you a list of command just used
!!
reexecute the previous one
!n
reexecute command n
!text
reexecute the most recent one beginning with text
!?text?
reexecute the most recent one containing text
06/03/10
Jianchun Wang
10
File System
 File types: directories, ordinary file, special file, symbolic links.
 Path: absolute/full path name, relative path name.
 Special directories: / ~ – $HOME . .. $cwd $PWD ~username.
 Commands:











cd [directory]
pwd
ls [file]
rm file, rmdir directory, rm –fr directory
mv file_source file_target
cp file_source file_target
ln -s file_source file_target
chmod:
ugoa +–= rwx
eg. chmod a+x file, chmod 755 file
mkdir (–m mode, –p)
cat, more, less
find, wc, sort, grep, head, tail, awk
06/03/10
Jianchun Wang
11
Secure Shell

Systems exchange security key during. Communication data
are encoded with security key.

Remote login using ssh: Open ssh, hummingbird exceed
security shell, PuTTy, …

Transfer remote files:



sftp [email protected]
scp [email protected]:remoteFileName ./newFileName
Your files are in ~/.ssh/:
authorized_keys2, id_ras, id_rsa.pub, known_hosts, config

Password free to access node B from node A:
1.
2.
Generate key on node A: ssh-keygen –t rsa
Append id_rsa.pub on A into authorized_keys2 on B.
06/03/10
Jianchun Wang
12
Basic Editing with emacs
 GNU emacs is written in LISP. For many standard extension, emacs
knows the grammar. It has many other powerful functions. You should
learn it if you just start.
 Configuration with ~/.emacs.
(add-hook 'fortran-mode-hook 'turn-on-font-lock)
(load (expand-file-name "$EMACSDIR/lhcb"))
 Basic commands (most of them can be accessed via menu):










<ctrl-x><ctrl-f>
<ctrl-x><ctrl-c>
<ctrl-x><ctrl-s>
<ctrl-k>
<ctrl-w>
<ctrl-y>
<ctrl-<space>>
<ctrl-g>
<ctrl-_>
<ctrl-s>
06/03/10
edit a file or directory
exit
save file
delete from cursor to end of line
delete region
restore what you have deleted
mark the beginning of a region
abort current command
undo last edit
search
Jianchun Wang
13
Run Job with SGE



Cluster configuration

Master:
hepc1

Submit hosts:
hepc1, hepc2

Excecution:
hepc2, node1-15
Commands ( try with ~jwang/For_Group/sample.job )

qsub your_job_script [your_options]

qsub -q [email protected] your_job_script [your_options]

qstat –f

qdel your_jobi_d
Notes

It is set to have only one queue per CPU

There is no time limit.

It is recommended to use /tmp/your_name to store large output files during
running and move them to designated directory at the end of your job in
script.
06/03/10
Jianchun Wang
14
ROOT
 Setup proper environment parameters:
 setenv ROOTSYS /lhcb/lib/lcg/external/ROOT/pro/slc4_ia32_gcc34/root
 setenv LD_LIBRARY_PATH .:$ROOTSYS/lib:/usr/lib
 Add $ROOTSYS/bin in your PATH
 Root resource file: ~/.rootrc
 Run root program




root –help
root rootHistogramFile
root
Quit with .q
You can get syntax.
It opens the root histogram file as _file0
 Copy example files: ~jwang/For_Group/hp1.root, example.C
06/03/10
Jianchun Wang
15
Interactive Draw of A Histogram
15:[email protected] root hp1.root
root[0]
new TBrowser
ROOT Files  hp1.root  Vetra  SyrCommonModeNoise SyrPedCms_24  hAdcValue
root [1] hAdcValue->Draw(“colz”)
06/03/10
Jianchun Wang
16
Interactive Fit of A Histogram

Draw histogram
ROOT Files  hp1.root  Vetra  SyrCommonModeNoise SyrUpset_24  hAllSignal

Start FitPanel
root [2] gStyle->SetOptFit(11111)
root [3] hAllSignal->SetFillColor(4)
root [4] hAllSignal->Draw("hist")
root [5] hAllSignal->GetFunction("gaus")->SetLineColor(2)
root [6] hAllSignal->GetFunction("gaus")->Draw("same")

Change X/Y range etc.
06/03/10
Jianchun Wang
17
Run C++ Code In ROOT
root [4] .L example.C
root [6] example("hp1.root",24)
06/03/10
Jianchun Wang
18
To Learn More
 Unix/Linux
 Any Unix / Linux book.
 Red Hat Linux web
https://www.redhat.com/docs/manuals/linux/
 Emacs
 GNU web site
http://www.gnu.org/software/emacs/manual/
 Root
 Manual: http://root.cern.ch/root/doc/RootDoc.html
 Classes reference: http://root.cern.ch/root/Reference.html
06/03/10
Jianchun Wang
19

similar documents