Author Topic: [SH] Shell scripting  (Read 3550 times)

0 Members and 1 Guest are viewing this topic.

Offline Krazed

  • x86
  • Hero Member
  • *****
  • Posts: 1822
    • View Profile
[SH] Shell scripting
« on: May 22, 2005, 11:51:00 pm »
I've recently, (today) gotten into shell scripting. I've written three scripts today, I'll post them here and let you guys discuss them.

We'll start with helloworld.sh.

Code: [Select]
#!/bin/bash

echo "Hello world bash script!"
echo "Writen by krazed of x86!"
echo "The first of many. :P"

#this script is pointless, shush.
#what directory are we in!?

pwd

#what's in this directory!?

ls

#and, what's the uptime on this boxs?

uptime

#how about the processes being ran?

ps -aux

#Okay, that's all for today, 'folks.
#Written by krazed of x86.
#E-Mail: krazedx86@gmail.com
#AIM: krazedx86

This is called cmdlisting.sh. It takes the contents of the command directorys and lists them into three different .txt files.

Code: [Select]
#!/bin/bash

echo "Command listing bash script."
echo "Purpose: Copy your command lists to three different text files."

# First, we start off with /usr/bin, the default commands.

ls /usr/bin > defaultcommands.txt
echo "Contents of /usr/bin written to defaultcommands.txt"
echo " "

# Okay, now we have copied the contents of /usr/bin into the file defaultcommands.txt, Next!
# Now, time for /bin, the system commands.

ls /bin > systemcommands.txt
echo "Contents of /bin written to systemcommands.txt"
echo " "

# Okay, contents of /bin are now in systemcommands.txt
# Let's move on to /usr/X11/bin, the X windows programs.

ls /usr/X11/bin > xwincommands.txt
echo "Contents of /usr/X11/bin written to xwincommands.txt"
echo " "

# Alright, last but not least, let's list your installed programs. /usr/local/bin

ls /usr/local/bin > installedprograms.txt
echo "Contents of /usr/local/bin written to installedprograms.txt"
echo " "
echo "Script executed, no errors, not bad for my second script ever, eh?"

# Okay, that's the script for yah.
# It's not too bad for my second script ever.
# This script written by krazed of the x86 crew.
# We're on IRC at irc.tehnetwork.org:6667 #x86.
# E-Mail: krazedx86@gmail.com AIM: krazedx86

And, this is the third one. This one is actually pretty nifty, it's me experimenting with ANSI color codes, and scripting in color.

Code: [Select]
#!/bin/bash

# A small shell script written so I could fuck around
# and get the hang of coding with colors in shell scripts.

# A full list of all the ANSI color codes.
#1m     -     Change text to hicolour (bold) mode
#4m     -        "    "   "  Underline (doesn't seem to work)
#5m     -        "    "   "  BLINK!!
#8m     -        "    "   "  Hidden (same colour as bg)
#30m    -        "    "   "  Black
#31m    -        "    "   "  Red
#32m    -        "    "   "  Green
#33m    -        "    "   "  Yellow
#34m    -        "    "   "  Blue
#35m    -        "    "   "  Magenta
#36m    -        "    "   "  Cyan
#37m    -        "    "   "  White
#40m    -     Change Background to Black
#41m    -        "       "      "  Red
#42m    -        "       "      "  Green
#43m    -        "       "      "  Yellow
#44m    -        "       "      "  Blue
#45m    -        "       "      "  Magenta
#46m    -        "       "      "  Cyan
#47m    -        "       "      "  White
#49m    -        "       "      "  Default background
#7m     -     Change to Black text on a White bg
#0m     -     Turn off all attributes.

echo -e "\x1B[34;49m This is blue text on default background."
echo -e "\x1B[32;49m This is green text on default background."
echo -e "\x1B[37;42m This is white text on green background."

# This script written by krazed of the x86 crew.
# We're on IRC at irc.tehnetwork.org:6667 #x86.
# E-Mail: krazedx86@gmail.com AIM: krazedx86

I re-wrote cmdlisting.sh so I could practice getting color codes down. So here it is, the new and improved, cmdlistingv2.

Code: [Select]
#!/bin/bash

echo -e "\x1B[34;49m" "Command listing bash script, version2. Rewritten 05/22/05."
echo -e "\x1B[34;49m" "Purpose: Copy your command lists to four different text files."
echo " "

# First, we start off with /usr/bin, the default commands.

ls /usr/bin > defaultcommands.txt
echo -e "\x1B[31;49m" "Contents of /usr/bin written to defaultcommands.txt"
echo " "

# Okay, now we have copied the contents of /usr/bin into the file defaultcommands.txt, Next!
# Now, time for /bin, the system commands.

ls /bin > systemcommands.txt
echo -e "\x1B[31;49m" "Contents of /bin written to systemcommands.txt"
echo " "

# Okay, contents of /bin are now in systemcommands.txt
# Let's move on to /usr/X11/bin, the X windows programs.

ls /usr/X11/bin > xwincommands.txt
echo -e "\x1B[31;49m" "Contents of /usr/X11/bin written to xwincommands.txt"
echo " "

# Alright, last but not least, let's list your installed programs. /usr/local/bin

ls /usr/local/bin > installedprograms.txt
echo -e "\x1B[31;49m" "Contents of /usr/local/bin written to installedprograms.txt"
echo " "
echo -e "\x1B[34;49m" "Script executed."
echo -e "\x1B[0m"

# Okay, that's the script for yah.
# This script written by krazed of the x86 crew.
# Script rewritten so I could fuck with color codes.
# We're on IRC at irc.tehnetwork.org:6667 #x86.
# E-Mail: krazedx86@gmail.com AIM: krazedx86
« Last Edit: May 23, 2005, 12:00:31 am by krazed »
It is good to be good, but it is better to be lucky.

Offline Quik

  • Webmaster Guy
  • x86
  • Hero Member
  • *****
  • Posts: 3262
  • \x51 \x75 \x69 \x6B \x5B \x78 \x38 \x36 \x5D
    • View Profile
Re: [SH] Shell scripting
« Reply #1 on: May 23, 2005, 12:03:17 am »
Shellcode > Shell Script
Quote
[20:21:13] xar: i was just thinking about the time iago came over here and we made this huge bomb and light up the sky for 6 min
[20:21:15] xar: that was funny

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [SH] Shell scripting
« Reply #2 on: May 23, 2005, 11:49:17 pm »
<newb> wtf is shell code? </newb>
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Krazed

  • x86
  • Hero Member
  • *****
  • Posts: 1822
    • View Profile
Re: [SH] Shell scripting
« Reply #3 on: May 24, 2005, 05:11:48 pm »
It is good to be good, but it is better to be lucky.