Category Archives: Linux (Ubuntu)

Linux / Unix: Shell Script Find Out In Which Directory Script File Resides

I need to find out in which directory my bash script resides so that I can read config file called .backup .ignore .target. For example, if my script resides in >/home/foo/script.sh, I need to read /home/foo/.{backup,ignore,target} files. How do I find out the current directory location and shell script directory location in Bash running on Linux or Unix like operating systems?

Read answer to: “Linux / Unix: Shell Script Find Out In Which Directory Script File Resides

Tweet this    Share on Facebook

Powered by WPeMatico

W: TMPDIR is Mounted noexec, Will Not Cache Run Scripts Error and Solution

I mount /tmp with nodev, nosuid, and noexec options to increase the security of my Linux based web server. And, whenever I ran apt-get install or apt-get upgrade command, I am getting the following error: Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.2.0-43-generic
Found initrd image: /boot/initrd.img-3.2.0-43-generic
....
ldconfig deferred processing now taking place
Processing triggers for initramfs-tools ...
update-initramfs: Generating /boot/initrd.img-3.2.0-43-generic W: TMPDIR is mounted noexec, will not cache run scripts. ....
...
How do I fix this problem without compromising security of the data or web-server?

Read answer to: “W: TMPDIR is Mounted noexec, Will Not Cache Run Scripts Error and Solution

Tweet this    Share on Facebook

Powered by WPeMatico

Linux: Log Everyone Out Of The System

I can login as root user on Debian or Ubuntu/RHEL/CentOS Linux based system. I need to log everyone off to install new kernel and/or hardware. How do I do this on Linux? What is the best way to logout ALL USERS remotely over the ssh based session in Linux like operating systems?

Read answer to: “Linux: Log Everyone Out Of The System

Tweet this    Share on Facebook

Powered by WPeMatico

Nginx Redirect Mobile / Smart Phone Traffic To Mobile Version Of the Web Site

I am a new nginx user and I would like to redirect all mobile / smart phone users from www.example.com to m.example.com domain. How do I detect a mobile phone browser in nginx? How do I redirect all mobile users to sub-domain using regex based rules? How can I automatically redirects visitors on mobile devices to its mobile version at http://m.example.com/ and also allow mobile devices to the desktop website at www.example.com if visiting via http://www.example.com/?desktop=true?

Read answer to: “Nginx Redirect Mobile / Smart Phone Traffic To Mobile Version Of the Web Site

Tweet this    Share on Facebook

Powered by WPeMatico

Awk Floating Point Number Addition Results Are Unexpected

I am using awk to grep ‘foo’ from a text file and cacluate sum of field # 7. But, result is rounded to an integer. I need exact result such as 385858.66 and not 385858 using the following command:

grep ‘foo’ 2012-2013.txt | awk ‘BEGIN{ sum=0.0}{ sub(“,”,””,$7); sum +=$7}END{ print “$” sum}’ $682444

I want $682444.57 as output. How can I force “awk” to do floating point math?

Read answer to: “Awk Floating Point Number Addition Results Are Unexpected

Tweet this    Share on Facebook

Powered by WPeMatico