Bash fun

Posted on June 15th, 2009 at 22:46, in Linux, Ubuntu.

Linux is awesome. I knew that! When you are completely bored and you have access to a terminal (and you are in the sudo-ers group) you can do this:

radu@enterprise:~$ sudo apt-get install cowsay
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  filters
The following NEW packages will be installed:
  cowsay
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/19.8kB of archives.
After this operation, 295kB of additional disk space will be used.
Selecting previously deselected package cowsay.
(Reading database ... 173410 files and directories currently installed.)
Unpacking cowsay (from .../cowsay_3.03-9.2_all.deb) ...
Processing triggers for man-db ...
Setting up cowsay (3.03-9.2) ...

Afterwards you could issue a command like this:

radu@enterprise:~$ fortune | cowsay -n -f tux.cow
 __________________________________________________________________________
/ In the first place, God made idiots; this was for practice; then he made \
| school boards.                                                           |
\                 -- Mark Twain                                            /
 --------------------------------------------------------------------------
   \
    \
        .--.
       |o_o |
       |:_/ |
      //   \ \
     (|     | )
    /'\_   _/`\
    \___)=(___/

Or, if you have a sick humor:

radu@enterprise:~$ fortune | cowsay -n -f sodomized.cow
 ________________________________________________________
< You will have domestic happiness and faithful friends. >
 --------------------------------------------------------
      \                _
       \              (_)
        \   ^__^       / \
         \  (oo)\_____/_\ \
            (__)\       ) /
                ||----w ((
                ||     ||>>

Let me see how do you have that fun in Windows, suckers!

Similar Posts:


17 Comments

Tudor said

on June 18th, 2009,

at 14:45 hours

Cool stuff :P But not as cool as

sudo su
cowsay -f tux “I see you” > /dev/pts/0

where /dev/pts/0 is another dude’s console :P

Radu said

on June 18th, 2009,

at 14:52 hours

Actually, I think it would be more fun to do something like:

[radu@WL-500W root]$ cowsay -f sodomized "I see you behind this cow!" > /dev/pts/1
 ____________________________
< I see you behind this cow! >
 ----------------------------
      \                _
       \              (_)
        \   ^__^       / \
         \  (oo)\_____/_\ \
            (__)\       ) /
                ||----w ((
                ||     ||>>

with the amendment that you should use another user’s console.

[...] Later edit: the fun continues here! [...]

Anonymus Gravatar

cowcant root said

on July 23rd, 2009,

at 10:38 hours

I have can do both cowsay and fortune as a user but not as root. Both were installed via root apt-get install cowsay fortune

But when trying either cmd as root I get:
-bash: cowsay: command not found
-bash: fortune: command not found

any ideas?

Thank you!

Radu said

on July 23rd, 2009,

at 11:22 hours

Why would you like to run it as root? The answer to this is that cowsay and fortune are not in the $PATH variable for root.

radu@tux:~$ echo $PATH
/opt/soapui/bin:/opt/maven/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/bin/X11:/usr/games
radu@tux:~$ sudo -i
root@tux:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
root@tux:~# cowsay
Command 'cowsay' is available in '/usr/games/cowsay'
The command could not be located because '/usr/games' is not included in the PATH environment variable.
-bash: cowsay: command not found

So the answer is either you do not use root for cowsay (I really do not see the point of doing this), either you add in the $PATH variable for root the folder /usr/games or you just use Tudor’s way of doing this described in his first comment.
Have fun!

Anonymus Gravatar

cowcant root said

on July 23rd, 2009,

at 12:34 hours

Forgot to say I use Linux Debian 5.0.1 Lenny.
Newbie :)
Actually I don’t want to use it as root, (been told should never use root except when needed) but I read that I need to, to do as root to message another user logged in like this:
cowsay -f moose I see you > /dev/pts/0
This cmd gets “denied” as a user

cowsay -f sodomized “I see you” > /dev/pts/1
cowsay -f sodomized “I see you” > /dev/pts/0
These cmds gets “event not found” as a user
(though I am logged in as two different users)

Anonymus Gravatar

cowcant root said

on July 23rd, 2009,

at 12:47 hours

Ok I retried the cmds, just an update.. if I remove the “!” in :
cowsay -f sodomized “I see you behind this cow!” > /dev/pts/1

Then I get the same error, with or without the quotes: ” ”
which is: -bash: /dev/pts/1: Permission denied
(as a user)
as su: bash: cowsay: command not found

I read Tudor had said on another post:
“PS: this requires root level access”

Thank you again :)

Radu said

on July 23rd, 2009,

at 14:04 hours

Tudor said sudo su. If you use sudo -i, as I used, it won’t work. For you to send that message with the exclamation mark, you just need to remove the quotes:

root@tux:/home/radu# cowsay -f sodomized I see you behind this cow! > /dev/pts/0
 ____________________________
< I see you behind this cow! >
 ----------------------------
                      _
                     (_)
           ^__^       / 
           (oo)_____/_ 
            (__)       ) /
                ||----w ((
                ||     ||>>

The first output of the sodomized cow was from BusyBox, on my router, which does not interpret the quotes like Ubuntu does.

P.S. Why are you afraid to use your email? If you use it, I wouldn’t have to approve every comment you make, only the first one registered with it. I’m not gonna sell it for spam…

Anonymus Gravatar

cowcant root said

on July 23rd, 2009,

at 14:16 hours

Radu thank you again.
Yes re sudo su:
sudo su
-bash: sudo: command not found

For my Debian its su which I believe is the same thing, yes?
So for su can’t cowsay
and for user can’t /dev/pts/1

Maybe I am misunderstanding the ‘sudo su’ thing?

Re the e-mail, to be honest, just a habit when registering isn’t required. Sorry I didn’t realize you had to approve each time so I have put my email this time :D

Radu said

on July 23rd, 2009,

at 15:03 hours

Try man sudo and see the difference between those options. If you try to use sudo as root, well that’s not possible. sudo is meant only for users other than root, but they must be in the sudoers list. If you have tried sudo as a regular user and found that “error”, you either are in the case mentioned in the previous phrase, either you have broken your hostname by not keeping consistency between /etc/hostname and /etc/hosts.

Anonymus Gravatar

cowcant root said

on July 24th, 2009,

at 09:14 hours

Thank you Radu. I didn’t know that. All along I thought su & sudo were thee same thing just different cmd’s for different OS’s. Wow ok from cowsay to fixing this lol…

After some digging I found that I didn’t have ‘sudo’ (http://www.binbash.eu/linux/58-debian-etch-notes) so I did:

aptitude install sudo 
No /etc/sudoers found... creating one for you.

Ok so now I try (as a user and as root) sudo
reply same for both:

sudo: unable to resolve host PTy990499a.servername.com

(*PTy990499a.servername.com I have changed, it’s not the real server name, just similar)

cat /etc/hostname

simply has PTy990499a.servername.com and this hostname can not be resolved (Dns unable to resolve..). Where as the servername.com part can be resolved, correctly. And the PTy990499a part is what I see on the console on each line, for example:

PTy990499a:~# cat /etc/hostname
PTy990499a.servername.com
PTy990499a:~# cat /etc/hosts
127.0.0.1       localhost
200/66.123.66   PTy990499a.servername.com.servername.com  PTy990499a
 
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

(*200/66.123.66 also not the real IP)

So I’m going to try to fix this myself, please don’t give away any clues :) and see if I can do this myself. Just a crazy busy day here. Will post when done or stuck :D
Thank you again Radu!

Anonymus Gravatar

cowcant root said

on July 25th, 2009,

at 05:03 hours

Sorry Radu; stuck :( and very frustrated.
This is what I have done and the edited replies. I posted here: http://pastebin.com/m45312224
as worried too long for here and felt like it was ruining your nice cosway post :D
I’m also very nervous that I’m messing with the host files. Since I only have remote access to this box it would be impossible to fix it if it went off line because I mess something up real good.

Thank you very much! :)

PS. I didn’t mean to come here to have you fix all of this for me, sorry…if you want me to take it to a forum to fix, I understand :) Thank you again Radu! :D

Anonymus Gravatar

cowcant root said

on July 26th, 2009,

at 07:09 hours

I’m back with a working sudo :D
sudo /etc/init.d/apache2 reload
[sudo] password for myname:
Reloading web server config: apache2.

But cowsay still can’t speak to another user. I’ve tried a variety of cmds:
sudo su cowsay -f moose I see you > /dev/pts/2
-bash: /dev/pts/2: Permission denied

sudo su cowsay -f moose I see you > sudo /dev/pts/2
su: invalid option — f
Usage: su [options] [LOGIN]

sudo su cowsay -f moose I see you > sudo su /dev/pts/2
su: invalid option — f
Usage: su [options] [LOGIN]

sudo cowsay -f moose I see you > /dev/pts/2
-bash: /dev/pts/2: Permission denied

sudo cowsay -f moose I see you > sudo /dev/pts/2
sudo: cowsay: command not found

cowsay -f moose I see you > sudo su /dev/pts/2
(no reply, and it didn’t say to user 2)

Any ideas? Thank you :D

Radu said

on July 26th, 2009,

at 12:01 hours

Yeah… I’ve got two ideas. First issue who in a terminal to see who is logged in and where. Then do what Tudor has shown you. Afterwards maybe you can send me some money for support. :P

Anonymus Gravatar

cowcant root said

on July 26th, 2009,

at 13:22 hours

sorry, didn’t post that one as it brought me back to original post:
sudo su
[sudo] password for myname:
*****:/home/myname# cowsay -f tux I see you > /dev/pts/1
bash: cowsay: command not found

Sorry, can’t send you money, but can send Thank Yous’ here :D
(I know not the same :(

Anonymus Gravatar

cowcant root said

on July 27th, 2009,

at 07:14 hours

I solved it. Thank you again Radu for your time and help. Please feel free to delete my non helpful post lol. I wouldn’t be offended.

Anonymus Gravatar

Florin said

on May 21st, 2010,

at 22:14 hours

Think you've got something to say?

For leaving comments including source code or terminal output, please use the the following tags like in the next example:

[language]
code lines
[/language]
where you substitute language with the programming laguage used throught the code example (for terminal output that would be bash), e.g:
[bash]
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
[/bash]

To see a list of all the supported languages, please check this page.

If you want to include code bits inline, please use the code tags like in the following example:

The <code>$USER</code> variable holds the current logged in username.

Subscribe without commenting


Bear