Skip to content

Instantly share code, notes, and snippets.

View davidcrx's full-sized avatar

David Creus davidcrx

View GitHub Profile
@davidcrx
davidcrx / readfile.cs
Created March 14, 2018 11:29
Read the file, count the rows and columns
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReadFile
{
class Program
{
@davidcrx
davidcrx / dhcp-router.txt
Last active March 20, 2018 17:34
DHCP Server
!Router R2 configuration
enable
conf t
interface serial 0/0/1
ip address 192.168.101.1 255.255.255.0
no shutdown
end
conf t
ip dhcp excluded-address 192.168.102.1 192.168.102.3
@davidcrx
davidcrx / pingall.sh
Created March 21, 2018 11:29
Programa que comprueba si los hosts estan disponibles (mediante ping)
#Programa que comprueba si los hosts estan disponibles (mediante ping)
date
cat /home/davidcrx/list.txt | while read output
do
ping -c 1 "$output" > /dev/null
if [ $? -eq 0 ]; then
echo "node $output is up"
#dialog --msgbox "Todo correcto" 10 20
else
echo "node $output is down"
CONTADOR=1
let MINUMERO=$(( $RANDOM %6 + 1)) #Numero aleatori del 1 al 6
echo ' '; echo 'Numero Aleatorio entre 1 y 6'
echo '***************************************************'
read -p "Digam el teu nom: " NOMBRE
echo '***************************************************'
echo ' ' ; echo ' '
read -p "Portes $CONTADOR intents. Digam un número: " NUMERO
#
until [ $NUMERO -eq $MINUMERO ]; do
#!/bin/bash
while read LINE; do
curl -o /dev/null --silent --progress-bar --head --write-out '%{http_code} %{time_starttransfer} %{url_effective}\n' "$LINE"
done < websites.lst
echo -e "\n"
echo -e "Code 200: Okei"
echo -e "Code 302: Okei (http)"
echo -e "Code 404: Not found"
#Comprovar número de paràmetres
#Mirar si una web està online
if [ $# -ne 1 ]; then
echo "Número de argumentos no validos, sólo se permite 1"
exit 1
fi
WEB=$1
code=`curl -s -I $1 | head -n 1 | cut -d ' ' -f2`
#!/bin/bash
mysqldump --databases db1 > "/$USER/mysql-backup/db1-$(date +'%Y-%m-%d').sql"
mysqldump --databases db2 > "/$USER/mysql-backup/db2-$(date +'%Y-%m-%d').sql"
mysqldump --databases db3 > "/$USER/mysql-backup/db3-$(date +'%Y-%m-%d').sql
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Número de argumentos no validos, sólo se permite 1"
exit 1
fi
if [ -f $1 ] && [ -n $1 ]; then
echo -e "Todo OK"
@davidcrx
davidcrx / adduser.sh
Created June 6, 2018 07:16
Afegir usuaris automàticament en un entorn LDAP a través d'un fitxer CSV. [BASH]
#!/bin/sh
# Author: David Creus
# Programa que automatitza la creació d'usuaris en un entorn OpenLDAP
#################################################################
#Verifiquem que el usuari que executa l'script es root #
#################################################################
if [ "$(id -u)" != "0" ]; then
echo "Tens que ser root per executar aquest script" 1>&2
exit 1
fi
@davidcrx
davidcrx / codesendmail.cs
Created March 15, 2018 09:39
Enviar correo con fichero adjunto
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Mail;