Its the end of your day at work and at the last moment , you were asked to run a script to generate a report. This script would take around 30 mins to run and you only have 5 mins to catch the bus that takes you home.. what do you do???
One option is for you to run the script as a backgroup nohup process and redirect logs to a file, get back home and look at the logs.
Screen is the other thing that can help you here. With screen you can leave the script running on the machine and get back home and connect back to see the output terminal instead of the log file.
How to use screen:
- screen -S "screen-name" to start a screen
eg: screen -S 70mm
This will start the screen-name with 70mm in it.
- screen -ls to list all screens
There is a screen on:
15902.70mm (Attached)
1 Socket in /var/run/screen/S-sanjeevn.
Attached means that you are right now inside the screen itself i.e: connected to the screen. You can start runnign the script here wil make it run continusoulsy
example:
while true
> do
> echo "Press [CTRL+C] to stop.."
> sleep 1
> done
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
- ctrl-a-d to detach from a screen
This will detach you form the screen and bring you back to the original terminal
[detached]
["user-name"@greenshot-dl image]
- screen -r "screen-name" to connect to a screen name obtained from the above command
eg:
screen -r 15902.70mm (obtained form the screen -ls command )
I installed two thridparty softwares freetds and unixodbc. After the customary installation steps of unixodbc. I installed freetds with the following set of commands
./configure --with-unixodbc=/usr/local make make install
Both the softwares generated a few so files and placed it under /usr/local/lib ( could be lib64 as well). If it places in lib64 , then you will not need to worry about the next few steps. However in my case the binaries were put into /usr/local/lib
To make the binaries available in the LD_LIBRARY_PATH, I followed the below steps
vi /etc/ld.so.conf; add /usr/local/lib i.e: the path where both freetds and unixodbc binaries are installed ldconfig ; this is run to include the newly added lib path into the LD_LIBRARY_PATH ldconfig -p | grep libtdsodb; to check if I will be able to find the newly added nbinaries eg: libtdsodb using the LD_LIBRARY_PATH set by the system
Just to check if my database connections were working
cp *.ini /usr/local/etc/ ; these ini's are pre configured with the database ip addresses and the
connection details To test if DB connects, use the below command
I was unable to execute any commands of cov01.exe on windows through hudson . whereas form the systems command prompt all commands worked fine. Through the hudson job , I was getting an error
Exception: cannot determine home directory
I could not find out the exact solution to this. But I did find a workaround. I had to set a few environment variables
set APPDATA=C:\Documents and Settings\build\Application Data set HOMEDRIVE=C: set HOMEPATH=\Documents and Settings\build
The problem seems to be because the Bullseye needs a home directory to start its operations which for some strange reason was not being set from the hudson job.
In Hudson/Jenkins, we were unable to open a new session through the browser. However what I noticed on looking at the hudson logs was that the sessions were running in the background. However we did find a SEVER error message which said the "(Too many open files)"
When I ran an lsof | wc -l it was almost at 1247 however as you can see from the below command , the limit for number of open files was set to 1024
# ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 139264 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 139264 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
To resolve this, and to increase the number of open files that are allowed in the system, I did the below..
edit the /etc/security/limits.conf and add the following. * soft nofile 4096 * hard nofile 4096
This means that for every user ( indicated by *) , the maximumm number of open files would be 4096. Instead of specifying *, you can specify the user-name . You will have to restart the service, and exit the session for the new ulimit values to be in place.
# ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 139264 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 4096 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 139264 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
A FEW commands that I had run to understand the various system parameters. Putting it down here for future reference