Enabling a seperate cron log in Debian

On Ubuntu, cron log can be seen in /var/log/cron. In Debian, cron log is by default part of syslog.

To enable a seperate cron log, do the following:

 #grep -in cron /etc/rsyslog.conf
58:#cron.*                              /var/log/cron.log
88:     cron,daemon.none;\

Now, edit that line (line num 58 in this example), and remove the comment symbol in front of cron.*

Now restart rsyslog service:

 #service rsyslog restart
Stopping enhanced syslogd: rsyslogd.
Starting enhanced syslogd: rsyslogd.

 

Note: If you can’t find /etc/rsyslog.conf, you will need to install rsyslog:

 #apt-get install rsyslog -y

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Pipe grep to less with color

You need to use the grep –color=always option with less -R

Eg:

#grep -inr 'robots' * --color=always | less -R

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Image has failed to upload due to an error – Missing a temporary folder

This error might have occured on WordPress for you: “Image has failed to upload due to an error – Missing a temporary folder”.

Reason?

  • It may be a permission issue for the php temporary folder
  • The php temp folder may not exist.

Solution?

  • Find the php.ini file for your webhost. 
  • Locate the temp folder
  • Create the temp folder if it does not exist
  • Give it proper permissions

In my case, I had transferred my site transhost, and hence this folder was actually missing.

My php.ini file (generated by i-mscp) was at this location: /var/www/fcgi/mysite/php5/php.ini

Once php.ini file was located, I needed to find the temp folder used by php:

#grep -in 'upload_tmp_dir' /var/www/fcgi/mydomain/php5/php.ini
875:upload_tmp_dir = "/var/www/virtual/mydomain//phptmp/"

Since this folder was missing, I created it and provided proper permissions and then restarted apache2:

#mkdir "/var/www/virtual/joel.co.in/phptmp/"
#chmod 755 "/var/www/virtual/joel.co.in/phptmp/"
#chown -R vu2003.www-data "/var/www/virtual/joel.co.in/phptmp/"
#service apache2 restart

Now, I could upload media files again.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Enabling roundcube plugins on i-mscp

The list of available plugins is at:

l /var/www/imscp/gui/public/tools/webmail/plugins/ | awk '{print $9;}'

acl
additional_message_headers
archive
autologon
database_attachments
debug_logger
emoticons
enigma
example_addressbook
filesystem_attachments
help
hide_blockquote
http_authentication
imscp_pw_changer
jqueryui
managesieve
markasjunk
new_user_dialog
new_user_identity
newmail_notifier
password
redundant_attachments
serverinfo
show_additional_headers
squirrelmail_usercopy
subscriptions_option
userinfo
vcard_attachments
virtuser_file
virtuser_query

Plugins are activated if the name of their directory is added to an array in the roundcube configuration file located at /var/www/imscp/gui/public/tools/webmail/config/main.inc.php

By default, i-mscp activates only one of those plugins: imscp_pw_changer

To activate the plugins additional_message_headers and archive, I would change the line:

$rcmail_config[‘plugins’] = array(‘imscp_pw_changer’);

To:

$rcmail_config[‘plugins’] = array(‘imscp_pw_changer’,’additional_message_headers’,’archive’);

To get the linenumber of this line, just type:

grep -in 'plugins' /var/www/imscp/gui/public/tools/webmail/config/main.inc.php

Just restart apache2 and refresh your browser and you will see that the plugin has been activated. The complete list of plugins can be found at http://trac.roundcube.net/wiki/Plugin_Repository

To add a new plugin, extract the downloaded archive to its own directory at /var/www/imscp/gui/public/tools/webmail/plugins and add its name to the array list in /var/www/imscp/gui/public/tools/webmail/config/main.inc.php

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Completely remove sendmail

At times it was noted that sendmail on my Debian system was not getting completely removed.

Thing tried:

apt-get remove sendmail*

It worked at times, and didnt at others.

But I were to try:

netstat -tulpn | grep :25
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      27878/sendmail: MTA

I’d find it again.

To find where it came from, I did:

 ls -l /proc/27878/
total 0
-r-------- 1 root root 0 Mar  5 12:47 auxv
-r--r--r-- 1 root root 0 Mar  5 11:58 cmdline
-rw-r--r-- 1 root root 0 Mar  5 12:47 coredump_filter
-r--r--r-- 1 root root 0 Mar  5 12:47 cpusete
lrwxrwxrwx 1 root root 0 Mar  5 12:47 cwd -> (deleted) /var/spool/mqueue
-r-------- 1 root root 0 Mar  5 12:47 environ
lrwxrwxrwx 1 root root 0 Mar  5 11:58 exe -> (deleted) /usr/lib/sm.bin/sendmail

Note that it shows /usr/lib/sm.bin/sendmail

However there is no /usr/lib/sm.bin, but there sure is a /usr/lib/sendmail

So I deleted them, and restarted the apache2 server.

 service apache2 restart
[ ok ] Restarting web server: apache2 ... waiting .
[email protected]:~/imscp# netstat -tulpn | grep :25
[email protected]:~/imscp# netstat -tulpn | grep 'sendmail'

Another thing that worked once was doing this:

chmod ugo=rw /etc/init.d/sendmail

In other words, I prevented it from running. But in the earlier instance there was no entry for sendmail under init.d

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Parse text files with assignments, and get the value – Bash

Suppose you have a text file containing the following:

strings=hello world

and you wanted to use the value of strings, which is “hello world” in your script

You can parse it with the following:

grep '^strings=' test | sed 's/strings=//g'

So the generic format is:

grep '^variablename=' filename | sed 's/variablename=//g'

The grep searches for a string beginning with ‘strings=’, in the file ‘test’, and outputs the following:

$grep '^strings=' test
strings=hello world

Next we have to remove the initial assignment part upto and including the ‘=’ sign, this is done by piping the output of grep, to sed.

Now the sed line substitutes the string “strings=” with an empty string. The substitution is done globally. Finally sed outputs just the value of the assigned variable.

Practical example:

I wanted to use the main User directory on the server, to make my backups more generic. I know that the file /etc/imscp/imscp.conf contains the following line:

USER_HOME_DIR = /var/www/virtual

So what I want is to get /var/www/virtual from this file, removing the assignment and spaces.

The solution is:

grep -i 'USER_HOME_DIR' imscp/imscp.conf | sed 's/USER_HOME_DIR[ ]=[ ]//'

which outputs:

/var/www/virtual

without the initial spaces. A space within a square brackets matches any number of spaces in the expression.

However, if you want to use these values in variables, you need to make minor adjustments to take care of variable escaping:

apache_home_var="USER_HOME_DIR"
apache_conf_file=/etc/imscp/imscp.conf
grep -i "$apache_home_var" "$apache_conf_file" | sed 's/'$apache_home_var'[ ]=[ ]//'

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Find all important php.ini files

 

cd /
[[email protected]] / #find . -iname php.ini -exec echo "Filename " {} \; -exec grep -in 'phpinfo' {} \;
Filename  ./var/www/fcgi/joel.co.in/php5/php.ini
Filename  ./var/www/fcgi/master/php5/php.ini
385:disable_functions = show_source, system, shell_exec, passthru, exec, phpinfo, shell, symlink
Filename  ./usr/local/src/imscp/master/imscp/configs/debian/fcgi/parts/php5/php.ini
Filename  ./usr/local/src/imscp/master/imscp/configs/debian/fcgi/parts/master/php5/php.ini
385:disable_functions = show_source, system, shell_exec, passthru, exec, phpinfo, shell, symlink
Filename  ./usr/local/src/imscp/configs/debian/fcgi/parts/php5/php.ini
Filename  ./usr/local/src/imscp/configs/debian/fcgi/parts/master/php5/php.ini
385:disable_functions = show_source, system, shell_exec, passthru, exec, phpinfo, shell, symlink
Filename  ./root/temp/htdocs/php.ini
Filename  ./root/temp/htdocs_perm_error/php.ini
Filename  ./etc/imscp/fcgi/parts/php5/php.ini
Filename  ./etc/imscp/fcgi/parts/master/php5/php.ini
385:disable_functions = show_source, system, shell_exec, passthru, exec, phpinfo, shell, symlink
Filename  ./etc/php5/cli/php.ini
Filename  ./etc/php5/cgi/php.ini

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Listing all useful system mounts in Note2

Use the following:

mount | grep -v 'block\/dm\|tmpfs\|devpts\|rootfs\|proc\|kernel\/debug\|sysfs\|cpuctl\|cpuacc'

Gives the following output:

/dev/block/mmcblk0p13 /system ext4 rw,relatime,barrier=1,data=ordered 0 0
/dev/block/mmcblk0p3 /efs ext4 rw,nosuid,nodev,noatime,barrier=1,journal_async_commit,data=ordered 0 0
/dev/block/mmcblk0p12 /cache ext4 rw,nosuid,nodev,noatime,errors=panic,barrier=1,journal_async_commit,data=ordered 0 0
/dev/block/mmcblk0p16 /data ext4 rw,nosuid,nodev,noatime,barrier=1,journal_async_commit,data=ordered,noauto_da_alloc,discard 0 0
/dev/fuse /storage/sdcard0 fuse rw,nosuid,nodev,noexec,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Bash script for splitting a filename, extension and path from fullpath

Call the function split_filenames with the first argument as the full filename with path. Alternately, set the variable fullfile to this value.

#!/bin/bash

split_filenames() {
# echo "Called with Arg: $1"
if [ ! "$1" = "" ]
then
fullfile=$1

fi
# echo I got this filename for processing $fullfile
filename=$(basename "$fullfile")
fname=$(basename "$fullfile")
nameonly=${filename%.*}
ext=${fname##*.}

echo "filename $filename"

filename=${fullfile%.*}
pathonly=${fullfile%/*}

if [ "$pathonly" = "$fullfile" ]
then
pathonly="$pat"
fi

echo "Path $pathonly"
echo "Name $nameonly"

chkper=$(echo $fullfile | grep -c "\.")
# echo "Number of periods:$chkper"

if [ ! "$chkper" = "0" ]
then
echo "Extension $ext"
else
echo "No extension"
fi

#out_file=$pathonly/$nameonly"_signed."$ext

}

for i in ~/Dropbox/SSH\ Keys/*
do
echo
echo Path and Name: $i
split_filenames "$i"
#cp "$i" testssh/
done[/code]
In the example, the main event calls the function from a loop which cycles through all the files in the specified directory.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Setting default grep options

I find myself using grep with

grep -i -n –color ‘string’ filename

most of the time. As you know, -i is for Ignore case, and -n for Number line, and –color colorizes the output.

An extremely useful thing to have is to set the environment variable

export GREP_OPTIONS="--color -i -n"

So I just need to type:

grep 'string' filename

and the output is already colorized, and has line number and case ignored.

Read more.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.