Sample Page

Magento database log cleaning

Log tables:

log_customer
log_visitor
log_visitor_info
log_url
log_url_info
log_quote
report_viewed_product_index
report_compared_product_index
report_event
catalog_compare_item

Cleaned by script:

php -f shell/log.php clean

Cleaned by Magento Admin (By default, it is disabled.):

From the Magento Admin Panel, select System > Configuration 
On the left, locate the Advanced menu and click System
From the System panel, click Log, and from the Enable Log Cleaning drop-down list, select Yes
In the Save Log Days field, enter 15 (The value is based on how much the traffics are)
Click Save Config

Clean those tables manually with Mysql client or phpMyAdmin (NOT recommend)

 

Source: https://docs.nexcess.net/article/how-to-perform-magento-database-maintenance.html

Docker USER and named volume

To secure docker, we use a specific user instead of root. We add the following code in Dockerfile.

RUN useradd -u 2000 wwwuser
USER wwwuser

Those code create user with uid=2000.
Since host volume is mounted as root user, all files and folders is readonly for user wwwuser. If the wwwuser needs to write files to volume, we can create a named volume for it.

docker volume create --driver local --opt type=tmpfs --opt device=tmpfs  --opt o=uid=2000,gid=2000,size=2g,mode=0750 myHomeVolume

Use the following command to run container

docker run -d -v myHomeVolume:/home/wwwuser --name myapps <image>

TO backup the data, taring all files at ‘/var/lib/docker/volumes/myHomeVolume/_data’ with root.

Using AWK

//print the first column
awk -F":" ' { print $1 } ' /etc/passwd  
// print 1st column and last column
awk -F":" ' { print $1, $NF} ' /etc/passwd 
//print 1st column of 1st ten records
awk -F":" ' NR==1,NR==10 { print $1 } ' /etc/passwd
//print 1st column length of 1st ten records 
awk -F":" ' NR==1,NR==10 { print length($1) } ' /etc/passwd 
// using printf to format output
awk -F":" ' NR==1,NR==10 { printf "%-8s %3d\n" , $1,$3 } ' /etc/passwd 
// add header and footer for output
awk -F":" '
BEGIN { printf "%-8s %-3s\n" , "User", "UID" }
NR==1,NR==10 { printf "%-8s %3d\n" , $1,$3 } 
END { print "============== END ============="} ' /etc/passwd
// add output filed separator between columns
awk -F":" ' { OFS="|";print $1, $NF } ' /etc/passwd
// condition
awk -F":" ' /^root/ { print $1, $NF } ' /etc/passwd
awk -F":" ' { if($1 ~ /root/) { print $1, $NF } }' /etc/passwd

 

Linux Job Interview Questions

  1. How can you see which kernel version a system is currently running?
uname -a  // Show hostname, current version, current release

uname -v  //Show current version

uname -r  // Show current release

2.How can you check a system’s current IP address?

ifconfig
ip addr show
ip addr show eth0

3. How do you check for free disk space?

df -ah

4. How dow you manage services on a system?

service <service name> status
systemctl status <service name>

5. How would you check the size of a directory’s contents on disk?

du -sh <directory name>

6. How would you check for open ports on a Linux machine?

netstat
sudo netstat  -tulpn

7. How do you check CPU usage for a process?

ps aux |grep <process name> 
top
htop

8. Dealing with Mounts

ls /mnt
mount <device/network drive> <mount point>
/etc/fstab

9. How do you look up something you don’t know?

man <command>
<command> --h
google

 

Open range ports via ufw or iptables

For UFW

ufw allow from any to any port 4000:4020 proto tcp

For iptables

iptables -A tableName -p tcp  --match multiport --dports port1,port2 -j ACCEPT
iptables -A tableName -p udp  --match multiport --dports port1,port2 -j DROP
iptables -A tableName -p protocol  --match multiport --dports portRange1:PortRange2 -j ACCEPT
iptables -A tableName -p tcp  --match multiport --sports port1,port2 -j ACCEPT
iptables -A tableName -p udp  --match multiport --sports port1,port2 -j DROP
iptables -A tableName -p protocol  --match multiport --sports portRange1:PortRange2 -j ACCEPT

SMTP setting for Drupal, Django, and WordPress

Drupal, Django, and WordPress are using localhost as SMTP server by default. But there is a way to use another SMTP server to send email.