How to track Process Launches in Linux

Suppose you want to know what processes get launched at a given time on your Linux box like Ubuntu, you can use Auditd. Run the following commands.

apt-get install auditd
auditctl -a task,always
ausearch -i -sc execve

Sources

logging – How can I log all process launches in Linux – Super User. http://superuser.com/questions/222912/how-can-i-log-all-process-launches-in-linux

How to find Crash Log of iOS Simulator

Suppose you do not have Xcode running, but want to view crash logs of your simulator, you can do that easily by visiting

~/Library/Logs/DiagnosticReports/

Here all crash log files can be found with .crash extension.

Note: you need to launch your app without Xcode in order to have the log updated.

Sources

Crash logs generated by iPhone Simulator? – Stack Overflow. http://stackoverflow.com/questions/1864479/crash-logs-generated-by-iphone-simulator

How to parse JSON Array in Swift using AFNetworking

Here I will describe how to parse a JSON array in Swift using AFNetworking for the request. Suppose your network request returns a JSON like

[
{'prop':'Property1'},
{'prop':'Property2'},
...
]

Here’s the code you want to use

// items
let manager = AFHTTPRequestOperationManager()
        
manager.GET("", parameters: nil,
     success: {
         (operation: AFHTTPRequestOperation!,
         responseObject: AnyObject!) in
         if let jsonArray = responseObject as? NSArray {
                    
              for propInfo in jsonArray {
                 let propObject = propInfo as! NSDictionary
                 let prop:String = propObject["prop"] as! String
                 print("property extracted: \(prop)")                
              }
          }             
      },
      failure: {
          (operation: AFHTTPRequestOperation!, error: NSError!) in
          print("Error: " + error.localizedDescription)
                
      }
)

How to use Screen

Screen is a handy tool for creating SSH sessions that withstand network failures as well as for making SSH terminals containing multiple sessions.

To start a screen session use the command:

screen

You can also give the session a name using the command

screen -S <session name>

To detach from a running screen session use the command:

Ctrl+A d

To list screen sessions use the command:

screen -ls

To resume a screen session use the command:

screen -r

Sources

How To Use Linux Screen. https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/

How to cleanly remove Exim 4 on Ubuntu

Run the following command:

apt-get remove exim4 exim4-base exim4-config exim4-daemon-light

All your configs stay on the server so that you can easily get mailing running again by installing it:

apt-get install exim4

Source

exim – How to cleanly remove Exim4 mail server on Ubuntu – Stack Overflow. http://stackoverflow.com/questions/12061358/how-to-cleanly-remove-exim4-mail-server-on-ubuntu

How to prevent execessive scraping on Website on Ubuntu Server

Add rules as follows:

iptables -A INPUT -p tcp --syn --dport 80 -m connlimit\
 --connlimit-above 15 --connlimit-mask 32 -j REJECT \
 --reject-with tcp-reset 

This will reject connections above 15 from one source IP.

iptables -A INPUT -m state --state RELATED,ESTABLISHED \
-m limit --limit 150/second --limit-burst 160 -j ACCEPT  

In this 160 new connections (packets really) are allowed before the limit of 150 NEW connections (packets) per second is applied.

Note: if your server runs UFW (Uncomplicated Firewall), then you shouldn’t run the commands directly. Instead, you need to replace INPUT with ufw-before-input in each line and put the lines in the file /etc/ufw/before.rules. Afterwards, restart UFW using the following command:

sudo service ufw restart

Source

Limit max connections per IP address and new connections per second with iptables – Unix & Linux Stack Exchange. http://unix.stackexchange.com/questions/139285/limit-max-connections-per-ip-address-and-new-connections-per-second-with-iptable

How to remove all iptables rules

Create a file /root/fw.stop with the following content:

#!/bin/sh
echo "Stopping firewall and allowing everyone..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

Make it executable and then run it on the terminal.

Source: http://www.cyberciti.biz/tips/linux-iptables-how-to-flush-all-rules.html