GPG: Tasks 101 
Common tasks:
[acool@localhost ~]$ gpg --version
...
[acool@localhost ~]$ gpg --gen-key
...
# make entropy faster
[acool@localhost ~]$ sudo rngd -r /dev/urandom
...
[acool@localhost ~]$ gpg --list-keys
...
# exports public key
[acool@localhost ~]$ gpg --export --armor
...
[acool@localhost ~]$ gpg --export-secret-key --armor
...
# symmetric-encrypting a file
[acool@localhost ~]$ gpg --symmetric --cipher-algo AES256 top-secret.txt
...
[acool@localhost ~]$ gpg --interactive --edit-key "gpg-id-email"
gpg> showpref
...
[acool@localhost ~]$ gpg --fingerprint "gpg-id-email"
...
[acool@localhost ~]$ gpg --delete-keys "gpg-id-email"

Pass
[acool@localhost ~]$ pass init "gpg-id-email"
...



12/19/2020 - Encrypt and decrypt existing file.

[acool@localhost ~]$ echo "Confidential information goes here." > secret-message.txt
[acool@localhost ~]$
[acool@localhost ~]$ # encrypt it!
[acool@localhost ~]$ gpg --output secret-message.txt.gpg --recipient acool.pgp@10-network.net --armor --encrypt secret-message.txt
[acool@localhost ~]$
[acool@localhost ~]$
[acool@localhost ~]$ cat secret-message.txt.gpg
-----BEGIN PGP MESSAGE-----

hQIMA2ZQHKXHI4G5AQ//f1JwJREZGa904w5Ev1svX/dbyydDb7FBowjnVG2Ne3eO
BZS1VqV+Zjq9j0HgQ6W86j4bYOwwqgW0YYtixBRr3+TFBoN8bBSxaMTLo6w+MHEL
iPJo1FIyDm5gYyljQBE4CLISJan9wsIIuSX4RcH+yNV7kYlK/eWJDstlX/1GW7bA
P6gcNpGNtliFwZZzsC88+qCOg3kX9iEBPcAmRUNg1Tk1s1AHX3MD5pO/dV8HIJ8N
Byti/jyd+X/DbJT6r8rDwwsY320vwNWU4QrLnsoRc34ce2q3V6avXKX9Fj+94xXo
5c00NzI55MVE9jdTDakD2H4xrI40trFg6pOB2JRrxeS7AUg4Ae+tRidAOP0qGgM9
jsOY+ToPFcetMwVNZ+Tw4d7VCN/4/vimHeZ6DRAo6kfqVTkJVVtkYvyRr6r0UxvO
Bdk0p7rmrhMu1jHAcwxSGSZZLKRPYe01W/WIbazF5Q3Mb6fmg8K6sqoRaFdiY036
XIx+QjjjG2PoLJlZ31LwSyQyFhd4hGIk0mbXmXFwY+Vo9cpToaTIcahqAY8wdieM
fwP/w5w2jbhNYYte69e+YC9C38uYMihX47IEtUGYhVUQYRRH085cYL/0Rc68uMDd
oiXIynlT7fzbSMwD6aNTYe3dRwKpd+ZJ8ri6FO9E0bbA3E3feJseLktpmRZxETTS
cQF9fN7hl7fFK7dU/KAdpNJz0ihRV9UofEOrEM1svtcPViLBF0oYNMv5qbtLgO0y
NU4mCjZHH+F00AouErS5VrDRC6/D748t0nNOlTLAp/0MONRBSKDqzDEM8pPB1AIX
jrDesP+iYqNgBnZe9qRVSXQ3
=65wR
-----END PGP MESSAGE-----
[acool@localhost ~]$
[acool@localhost ~]$
[acool@localhost ~]$ #decrypt it!
[acool@localhost ~]$ gpg --output output.txt --decrypt secret-message.txt.gpg
[acool@localhost ~]$
[acool@localhost ~]$ # see decrypted information
[acool@localhost ~]$ cat output.txt
Confidential information goes here.
[acool@localhost ~]$



[ view entry ] ( 1255 views )   |  print article
CIsco: Aironet 1242G Autonomos AP Configuration 
Cisco 1242G Access Point Configuration (AIR-LAP1242G-A-K9), Image: c1240-k9w7-mx.124-21a.JA1 Autonomous AP
/*reset everything*/
ap#write erase
ap#reload
ap>en
Password: Cisco //default password
ap#

/*configure AP's ip address*/
ap#config t
ap(config)#interface BVI1
ap(config-if)#ip address 192.168.0.100 255.255.255.0
ap(config-if)#no shut

/*other stuff*/
ap(config)#ip name-server 4.2.2.2 8.8.8.8
ap(config)#ip default-gateway 192.168.0.1
ap(config)#ip domain name example.com

/* configure ssid */
ap(config)#dot11 ssid 1242G
ap(config-ssid)#authentication open
ap(config-ssid)#authentication key-management wpa version 2
ap(config-ssid)#wpa-psk ascii 123456789 // psk
ap(config-ssid)#guest-mode //broadcasts ssid

/* associate ssid 1242G to the radio*/
ap(config)#interface dot11radio 0
ap(config-if)#encryption mode ciphers aes-ccm
ap(config-if)#ssid 1242G

/*ssh config*/
ap(config)#crypto key generate rsa //chose 1024
ap(config)#aaa new-model
ap(config)#aaa authentication login default local //use local database
ap(config)#username admin password admin

/*defaults http password*/
admin/Cisco

[ view entry ] ( 1385 views )   |  print article
PHP: Poor man's alternative to array_chunk 
Useful when having to insert a large set of data in chunks to a databse:
<?php
$numbers=array (
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
'11',
);

$output = array();

foreach($numbers as $i=>$number)
{
$output[]= $number;

if(($i+1) % 3 == 0 || $i==count($numbers)-1)//last key
{
var_dump($output);
$output=array();
}
}

The above outputs:
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "3"
}
array(3) {
[0]=>
string(1) "4"
[1]=>
string(1) "5"
[2]=>
string(1) "6"
}
array(3) {
[0]=>
string(1) "7"
[1]=>
string(1) "8"
[2]=>
string(1) "9"
}
array(2) {
[0]=>
string(2) "10"
[1]=>
string(2) "11"
}

http://stackoverflow.com/questions/3549 ... -iteration

Thank you very much for your time !!!!!!

[ view entry ] ( 1373 views )   |  print article
BASH: Looping through all lines in a file 
Content of getThem.sh :
cd logos;

while read line; do

# test if line starts with "assets"
if [[ $line =~ ^asset.* ]]; then
#prepend domain
line="http://www.soy-example.com/$line"
fi

# test if line starts with "/assets"
if [[ $line =~ ^/asset.* ]]; then
# prepend domain
line="http://www.soy-example.com$line"
fi

# download this sucker
wget $line

done < ../soyFranquiciasLogos.txt


[ view entry ] ( 1268 views )   |  print article
CentOS 6.5 : Iptables NAT (Masquerade) 
CentOS 6.5 NAT

Topology:


Client1
+------+
+----+ |
+ 192.168.1.131 | +------+
+---------------+ | |
| | v |
| | +------+ |
| Internet +------------+ +------------+
| | +------+ |
| | Gateway ^ |
+---------------+ | |
| | +------+
| +----+ |
172.16.75.1 + +------+

Gateway's interfaces:
- WLAN0 outside (192.168.1.131/24), this network is my home's regular LAN connected to the internet
- ETH0 inside (172.16.75.1/24)

Assumptions:
DHCP server is set in the gateway servicing clients in ETH0, default gateway is ETH0's ip with dns servers: 4.2.2.2,4.2.2.1


*Enable IP forwarding(cat /proc/sys/net/ipv4/ip_forward)
[root@gateway ~]# sysctl -w net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1

*Set default policies to ACCEPT
[root@gateway ~]# iptables -P INPUT ACCEPT
[root@gateway ~]# iptables -P OUTPUT ACCEPT
[root@gateway ~]# iptables -P FORWARD ACCEPT

*Reset all rules in filter and nat tables, we want to be in full control ;)
[root@gateway ~]# iptables -t nat --flush
[root@gateway ~]# iptables -t filter --flush

*Verify we have no rules
[root@gateway ~]# iptables -t filter -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@gateway ~]#
[root@gateway ~]#
[root@gateway ~]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

*Save our changes so far
[root@gateway ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

*Enable NAT, wlan0 is our outside interface. This is where the magic happens.
[root@gateway ~]# iptables --table nat --append POSTROUTING --out-interface wlan0 -j MASQUERADE

* Save and restart
[root@gateway ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@gateway ~]# service iptables restart
iptables: Setting chains to policy ACCEPT: nat filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]

* Verify once more
[root@gateway ~]# iptables -t filter -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@gateway ~]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


* Clients in the inside interface(eth0) should now be able to ping the internet :)
[acool@client1 ~]$ 
[acool@client1 ~]$ ping -c 2 yahoo.com
PING yahoo.com (98.138.253.109) 56(84) bytes of data.
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=1 ttl=41 time=78.1 ms
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=2 ttl=41 time=84.5 ms

--- yahoo.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 78.154/81.349/84.544/3.195 ms
[acool@client1 ~]$


* Security
[root@gateway ~]# iptables -A INPUT -i wlan0 -m state --state ESTABLISHED,RELATED -j ACCEPT #allow incoming connections internally initiated
[root@gateway ~]# iptables -A INPUT -i wlan0 -p tcp --dport 22 -j ACCEPT # allow ssh
[root@gateway ~]# iptables -A INPUT -i wlan0 -j DROP # drop everything else


* Save & restart
[root@gateway ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@gateway ~]# service iptables restart
iptables: Setting chains to policy ACCEPT: filter nat [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]



* Verify (only the filter table should have changes)
[root@gateway ~]# iptables -t filter -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
DROP all -- anywhere anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@gateway ~]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@gateway ~]#
[root@gateway ~]#
[root@gateway ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 00:24:d2:de:4e:92 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.131/24 brd 192.168.1.255 scope global wlan0
inet6 2002:68af:f6e8:0:224:d2ff:fede:4e92/64 scope global dynamic
valid_lft 30sec preferred_lft 20sec
inet6 fe80::224:d2ff:fede:4e92/64 scope link
valid_lft forever preferred_lft forever
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:13:77:bb:9a:e7 brd ff:ff:ff:ff:ff:ff
inet 172.16.75.1/16 brd 172.16.255.255 scope global eth0
inet6 fe80::213:77ff:febb:9ae7/64 scope link
valid_lft forever preferred_lft forever
[root@gateway ~]#
[root@gateway ~]#
[root@gateway ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:13:77:BB:9A:E7
inet addr:172.16.75.1 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::213:77ff:febb:9ae7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:43985 errors:0 dropped:0 overruns:0 frame:0
TX packets:49958 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6091788 (5.8 MiB) TX bytes:50032578 (47.7 MiB)
Interrupt:18

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:44 errors:0 dropped:0 overruns:0 frame:0
TX packets:44 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6594 (6.4 KiB) TX bytes:6594 (6.4 KiB)

wlan0 Link encap:Ethernet HWaddr 00:24:D2:DE:4E:92
inet addr:192.168.1.131 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: 2002:68af:f6e8:0:224:d2ff:fede:4e92/64 Scope:Global
inet6 addr: fe80::224:d2ff:fede:4e92/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:82964 errors:0 dropped:0 overruns:0 frame:0
TX packets:59507 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:73241396 (69.8 MiB) TX bytes:9284164 (8.8 MiB)

[root@gateway ~]#


* Client IP
[acool@client1 ~]$ ifconfig enp0s25
enp0s25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.75.3 netmask 255.255.255.0 broadcast 172.16.75.255
inet6 fe80::6ab5:99ff:fef8:6ecc prefixlen 64 scopeid 0x20<link>
ether 68:b5:99:f8:6e:cc txqueuelen 1000 (Ethernet)
RX packets 12678 bytes 7212505 (6.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16512 bytes 2645234 (2.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xd7400000-d7420000



NOTE: Use the -v to get more details:
[root@gateway ~]# iptables -t filter -L -v 
Chain INPUT (policy ACCEPT 285 packets, 23628 bytes)
pkts bytes target prot opt in out source destination
7 609 ACCEPT all -- wlan0 any anywhere anywhere state RELATED,ESTABLISHED
0 0 ACCEPT tcp -- wlan0 any anywhere anywhere tcp dpt:ssh
49 3562 DROP all -- wlan0 any anywhere anywhere

Chain FORWARD (policy ACCEPT 259 packets, 102K bytes)
pkts bytes target prot opt in out source destination

Chain OUTPUT (policy ACCEPT 209 packets, 28461 bytes)
pkts bytes target prot opt in out source destination
[root@gateway ~]#
[root@gateway ~]#
[root@gateway ~]#
[root@gateway ~]# iptables -t nat -L -v
Chain PREROUTING (policy ACCEPT 61 packets, 4875 bytes)
pkts bytes target prot opt in out source destination

Chain POSTROUTING (policy ACCEPT 1 packets, 116 bytes)
pkts bytes target prot opt in out source destination
37 2292 MASQUERADE all -- any wlan0 anywhere anywhere

Chain OUTPUT (policy ACCEPT 8 packets, 631 bytes)
pkts bytes target prot opt in out source destination
[root@gateway ~]#




[ view entry ] ( 1316 views )   |  print article
KVM-Qemu VM Setup in CentOS 6.6 Minimal :) 
Follow these simple steps to install a VM in a minimal installation of CentOS 6.6 :

[acool@localhost ~]$ # 1.- install all these
[acool@localhost ~]$ sudo yum groupinstall "Virtualization Platform" "Virtualization Tools"
[acool@localhost ~]$ sudo yum install python-virtinst
[acool@localhost ~]$ sudo yum install bridge-utils
[acool@localhost ~]$
[acool@localhost ~]$ # 1.a- dd image from CD-ROM
[acool@localhost ~]$ sudo dd if=/dev/sr0 of=/usr/share/CentOS-6.6.iso
[acool@localhost ~]$
[acool@localhost ~]$ # 2.- start this
[acool@localhost ~]$ sudo service libvirtd start
[acool@localhost ~]$ sudo chkconfig libvirtd on
[acool@localhost ~]$
[acool@localhost ~]$ # 3.- modify eth0 and create network bridge file
[acool@localhost ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=90:2B:34:10:25:C0
TYPE=Ethernet
UUID=c74e1b53-a135-4573-ac74-8fd00b06a7ea
ONBOOT=yes
NM_CONTROLLED=no
BRIDGE=br0
[acool@localhost ~]$
[acool@localhost ~]$ cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.45
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=4.2.2.2
DNS2=4.2.2.1
DNS3=8.8.8.8
[acool@localhost ~]$ # 4.- restart networking
[acool@localhost ~]$ sudo service network restart
[acool@localhost ~]$
[acool@localhost ~]$ # 5.- put all these parameters in a file
[acool@localhost ~]$ cat virt-install.sh
sudo virt-install --connect qemu:///system \
-n vm20 \
-r 1024 \
--vcpus=2 \
--disk path=/var/lib/libvirt/images/vm20.img,size=12 \
-c /usr/share/CentOS-6.6.iso \
--graphics vnc \
--noautoconsole \
--os-type linux \
--accelerate \
--network=bridge:br0 \
--hvm
[acool@localhost ~]$
[acool@localhost ~]$ # 6.- create VM !!
[acool@localhost ~]$ ./virt-install.sh

Starting install...
Allocating 'vm20.img' | 12 GB 00:00
Creating domain... | 0 B 00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
[acool@localhost ~]$
[acool@localhost ~]$ # 7.- make sure it's running
[acool@localhost ~]$ sudo virsh list --all
Id Name State
----------------------------------------------------
1 vm20 running
[acool@localhost ~]$
[acool@localhost ~]$
[acool@localhost ~]$ # In another computer, open Virtual Machine Manager and connect to 192.168.1.45 and install linux in vm20 :)


[ view entry ] ( 1256 views )   |  print article
Python 101: Learning by doing. 
Looping through a dictionary (aka map):

Python 2.7.5
>>> map = {50+i:i for i in range(10)}
>>> map
{50: 0, 51: 1, 52: 2, 53: 3, 54: 4, 55: 5, 56: 6, 57: 7, 58: 8, 59: 9}
>>> for key, value in map.iteritems():
... print key,'-',value
...
50 - 0
51 - 1
52 - 2
53 - 3
54 - 4
55 - 5
56 - 6
57 - 7
58 - 8
59 - 9
>>>

Python 3.3.2
>>> map = {50+i:i for i in range(10)}
>>> map
{50: 0, 51: 1, 52: 2, 53: 3, 54: 4, 55: 5, 56: 6, 57: 7, 58: 8, 59: 9}
>>> for key, value in map.items():
... print(key,' - ',value)
...
50 - 0
51 - 1
52 - 2
53 - 3
54 - 4
55 - 5
56 - 6
57 - 7
58 - 8
59 - 9
>>>


Fetching url data:

Python 2
[aesteban@localhost corpemployees-filtered]$ python
Python 2.7.5 (default, Apr 10 2015, 08:09:05)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import urllib
>>> urllib.urlopen('https://graph.facebook.com/?id=http://www.barney.com').read()
'{"id":"http:\\/\\/www.barney.com","shares":792}'

Python 3
[aesteban@localhost corpemployees-filtered]$ python3
Python 3.3.2 (default, Dec 4 2014, 12:49:00)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import urllib.request
>>>
>>> urllib.request.urlopen('https://graph.facebook.com/?id=http://www.barney.com').read()
b'{"id":"http:\\/\\/www.barney.com","shares":792}'


[ view entry ] ( 1474 views )   |  print article
MySQL: Loading a TSV file into a table. 
1.- The column names are in the first line, get them:
[aesteban@localhost BizEquityData]$ head -1 bizDataFile.tsv | tr '\t' '\n'
id
name
dbaname
address
city
state
postcode
latitude
longitude
phone
faxphone
contact
firstname
lastname
email
yearestablished
businessstatus
webaddress
corpemployees
localemployees
corpamount
localamount
localamount
stockexchangecode
stocktickersymbol
ceoname
cioname
cfoname
name
code

1a..- find out total lines in file:
[aesteban@localhost BizEquityData]$ cat bizDataFile.tsv | wc -l
1785338

2.- Create a table, rename any duplicate field names:
CREATE TABLE `bizDataTable` (
id varchar(255),
name varchar(255),
dbaname varchar(255),
address varchar(255),
city varchar(255),
state varchar(255),
postcode varchar(255),
latitude varchar(255),
longitude varchar(255),
phone varchar(255),
faxphone varchar(255),
contact varchar(255),
firstname varchar(255),
lastname varchar(255),
email varchar(255),
yearestablished varchar(255),
businessstatus varchar(255),
webaddress varchar(255),
corpemployees varchar(255),
localemployees varchar(255),
corpamount varchar(255),
localamount varchar(255),
localamount2 varchar(255),
stockexchangecode varchar(255),
stocktickersymbol varchar(255),
ceoname varchar(255),
cioname varchar(255),
cfoname varchar(255),
name2 varchar(255),
code varchar(255)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

3.- Connect to the server and load the local file:
[aesteban@localhost BizEquityData]$ mysql -u USERNAME -h dev.example.com -p --local-infile bizDataDB
MySQL [bizDataDB]> load data local infile '/home/aesteban/Documents/BizEquityData/bizDataFile.tsv' into table bizDataTable fields terminated by '\t' lines terminated by '\n' ignore 1 lines;

MySQL [bizData]> select count(*) from bizDataTable;
+----------+
| count(*) |
+----------+
| 1785337 |
+----------+
1 row in set (0.00 sec)


Enjoy!!

BONUS: Dump select statement locally as a TSV file:
[aesteban@localhost FilteredReports]$ mysql -u USERNAME -h dev.example.com -p bizDataDB -e "select * from bizDataTable where email != 'NULL'" > bizData_email.tsv


If it's a CSV file, some fields may contain a comma, try something like the following:
MySQL [jupiter]> load data local infile 'e360Data.csv' into table e360MasterOnline fields optionally enclosed by '"' terminated by ',' lines terminated by '\n' ignore 1 lines;



[ view entry ] ( 1510 views )   |  print article
BASH 101: Dollar sign madness 
positional parameters, parameters passed to script.
$1, $2, $3, ... 

It's an array-like construct of all positional parameters, {$1, $2, $3 ...}.
"$@" 

It's the IFS expansion of all positional parameters, $1 $2 $3 ....
"$*" 

It's the number of positional parameters.
$# 

current options set for the shell.
$- 

pid of the current shell (not subshell).
$$ 

most recent parameter (or the abs path of the command to start the current shell immediately after startup).
$_ 

It's the (input) field separator.
$IFS 

It's the most recent foreground pipeline exit status.
$? 

It's the PID of the most recent background command.
$!

It's the name of the shell or shell script.
$0


http://stackoverflow.com/questions/5163 ... -variables

[ view entry ] ( 1295 views )   |  print article
BASH 101: Functions 
EXAMPLE A) Declaring a function in sum.sh script:
#!/usr/bin/bash

sum()
{
echo $1 + $2 | bc
}

# call function and pass cli
# parameters to function
sum $1 $2

Calling script:
[aesteban@localhost ~]$ ./sum.sh 1.4 1.3
2.7

EXAMPLE B) A different way to write sum.sh script:
#!/usr/bin/bash

sum()
{
RESULT=$(echo $1+$2 | bc) # or: RESULT=`echo $1+$2 | bc`
}

sum $1 $2

echo $RESULT

Calling modified script:
[aesteban@localhost ~]$ ./sum.sh 1.7 1.2
2.9

EXAMPLE C) Another way to write the same crap:
#!/usr/bin/bash

sum()
{
echo $1+$2 | bc
}

SUMRESULT=`sum $1 $2`

echo $SUMRESULT

Calling it:
[aesteban@localhost ~]$ ./sum.sh 2.9 3
5.9


[ view entry ] ( 1340 views )   |  print article

<<First <Back | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Next> Last>>


2024 By Angel Cool