You are not logged in.

#1 2008-02-16 02:07:34

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 679
Website

Pacman Info for Conky

It's nothing special so don't get your hopes up

#!/bin/bash
# use ${execi 5 pacstatus 5} in .conkyrc to display pacman information.
# the number given after pacstatus determines how many lines of history you would like shown
pacman -V | grep Pacman | cut -d " " -f 20-
echo
echo "last cmd - " `cat ~/.bash_history | grep "pacman " | tail -n1`
echo "last Sy - " `cat /var/log/pacman.log | grep sync | tail -n1 | cut -d "[" -f 2 | cut -d "]" -f -1`
echo "last Su - " `cat /var/log/pacman.log | grep "full system" | tail -n1 | cut -d "[" -f 2 | cut -d "]" -f -1`
echo
echo "last "$1" installed"
cat /var/log/pacman.log | grep installed | tail -n $1 | cut -d " " -f 4,5
echo
echo "last "$1" removed"
cat /var/log/pacman.log | grep removed | tail -n $1 | cut -d " " -f 4,5

0802conky.jpg

Last edited by gazj (2010-03-06 14:31:05)

Offline

#2 2008-02-16 02:45:37

Raisuli
Member
Registered: 2007-09-28
Posts: 135

Re: Pacman Info for Conky

hey, that looks really nice. Will try it out as soon as I get home. Thanks!

Offline

#3 2008-02-16 12:22:35

tami
Member
From: Norway, Oslo
Registered: 2007-11-10
Posts: 58
Website

Re: Pacman Info for Conky

gazj wrote:

It's nothing special so don't get your hopes up

..actually it's very nice and useful (!) script - working splendidly - thank you very much for sharing it.

Kind regards,
tami


"Possession means worries and luggage bags one has to drag along." Little My wink

Offline

#4 2008-02-16 12:41:59

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 679
Website

Re: Pacman Info for Conky

Thank you both, glad you find it useful

Offline

#5 2008-02-28 14:46:32

koch
Member
From: Germany
Registered: 2008-01-26
Posts: 369

Re: Pacman Info for Conky

great stuff but i have one question...

the script does not have acces to /root and the "last cmd" displays only commands typed in by normal users. how can i display root-commands in this line...

echo "last cmd - " `cat  ~/.bash_history | grep "pacman " | tail -n1`

Offline

#6 2008-02-28 14:59:25

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 679
Website

Re: Pacman Info for Conky

koch wrote:

great stuff but i have one question...

the script does not have acces to /root and the "last cmd" displays only commands typed in by normal users. how can i display root-commands in this line...

echo "last cmd - " `cat  ~/.bash_history | grep "pacman " | tail -n1`

You would need to change the line to this

echo "last cmd - " `cat  /root/.bash_history | grep "pacman " | tail -n1`

The problem is you would need access to root's home folder to do this (it's only read access so should be fine).  Use this command as root to achive this

chmod o+x /root

I haven't tested but it should work. smile

Or you can setup sudo then all your pacman commands can be ran as a normal user.  That's how mine is currently configured.

Hope that helps

Offline

#7 2008-02-28 15:11:19

koch
Member
From: Germany
Registered: 2008-01-26
Posts: 369

Re: Pacman Info for Conky

thanks, will try it in few minutes. some stuff to do here but your suggestion is exactly what i thought about. i am not very familiar with this stuff but learning.
i will post if it works without sudo, don't wanna use it.

edit: no, doesn't work.:(

Last edited by koch (2008-02-28 15:23:24)

Offline

#8 2008-02-28 15:28:45

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 679
Website

Re: Pacman Info for Conky

Sorry my fault, make that

chmod o+rx /root

and

chmod o+r /root/.bash_history

Last edited by gazj (2008-02-28 15:30:00)

Offline

#9 2008-02-28 15:57:48

koch
Member
From: Germany
Registered: 2008-01-26
Posts: 369

Re: Pacman Info for Conky

it works, thanks again.
i thought about trying it by myself but i didn't want to make changes to /root when i am not sure about it. no unnessesary chmods without asking someone who is more familiar with this.

Offline

#10 2008-02-28 16:04:57

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 679
Website

Re: Pacman Info for Conky

Familiar - yes, dare give you the instructions if I wasn't confident they wouldn't screw your system - never smile

Glad it worked.

Offline

#11 2008-02-28 16:29:35

carlocci
Member
From: Padova - Italy
Registered: 2008-02-12
Posts: 368

Re: Pacman Info for Conky

I wouldn't chmod 644 root's .bash_history: that way any user could read the commands you gave as root!
I'd rather add my user to root's group and chmod 640.
Or, as root

gpasswd -a username root
chmod 750 /root
chmod 640 /root/.bash_history

Last edited by carlocci (2008-02-28 16:34:19)

Offline

#12 2008-02-28 16:47:23

koch
Member
From: Germany
Registered: 2008-01-26
Posts: 369

Re: Pacman Info for Conky

big_smile
i was just starting to read about chmod again but this is faster, thanks.

Offline

#13 2008-02-28 17:38:40

carlocci
Member
From: Padova - Italy
Registered: 2008-02-12
Posts: 368

Re: Pacman Info for Conky

Not quite a nice thing to state smile
You'd better read about chmod, it's quite easy (and it introduces you to bitmasks too!)

chmod XXX filename.file

The first X is for the owner, the second for the group, the third for all others.
You can see the owner and the group of the file with ls -l, you can change them with

chown owner:group filename.file

So what numbers can you use?
4 means read
2 means write
1 means execute
You just need to sum them up, so chmod 666 makes a file editable and readable by everyone, chmod 550 makes a file executable and readable by the owner and the group and so on.

You would be probably wondering why 1,2 and 4 have been chosen instead of 1,10,100 (which would be the most readable) or 1,3,5 (which is just another triplet).

The man page of chmod says this:

NAME
       chmod - change file mode bits

If we convert them to binary
1 becomes 1
2 becomes 10
4 becomes 100
Which is just as readable and easy as 1, 10, 100 decimal.
So we need only 3 bits per user, 9 bits in total (+3 for special flags) per file.
This way the biggest number we can have is 111 binary, which is just 7 decimal and we can state the file permissions with only 3 (4 if you want to state the special flags) numbers.
Quite neat, if you consider the alternative, chmod u=rwx,g=rx,o=rx filename.file
For once, working "low level" it's easier and simpler.

Last edited by carlocci (2008-02-28 17:39:45)

Offline

#14 2008-02-28 17:44:13

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 679
Website

Re: Pacman Info for Conky

I wouldn't wan to add my user to the group root, you could end up have write permissions to some of root's files or config files.  If you are really concerned.  Create a new group then change the permissions of roots bash_history so that the group is no longer root.  Then add yourself to that new group.

There are many workarounds and none are really perfect smile

Offline

#15 2008-02-28 17:46:18

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Pacman Info for Conky

or rather change the owner of /root/.bash_history.. chmod root:username /root/.bash_history .. because by putting yourself in the root group, you probably open more files to yourself than you really intend on doing.  this way would only allow access to this file.  i am still against this whole allowing a user to read root's history, but this i guess would be one of the more secure ways..

edit: gazj you bastard! tongue

Last edited by rson451 (2008-02-28 17:46:51)


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#16 2008-02-28 17:49:33

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 679
Website

Re: Pacman Info for Conky

rson451 wrote:

or rather change the owner of /root/.bash_history.. chmod root:username /root/.bash_history .. because by putting yourself in the root group, you probably open more files to yourself than you really intend on doing.  this way would only allow access to this file.  i am still against this whole allowing a user to read root's history, but this i guess would be one of the more secure ways..

edit: gazj you bastard! tongue

Great minds and all that big_smile

Offline

#17 2008-02-28 18:41:32

cucullus
Member
From: Moscow, Russia
Registered: 2007-07-07
Posts: 67

Re: Pacman Info for Conky

please share your weather forecast solution

Offline

#18 2008-02-28 20:55:11

carlocci
Member
From: Padova - Italy
Registered: 2008-02-12
Posts: 368

Re: Pacman Info for Conky

rson451 wrote:

or rather change the owner of /root/.bash_history.. chmod root:username /root/.bash_history .. because by putting yourself in the root group, you probably open more files to yourself than you really intend on doing.  this way would only allow access to this file.  i am still against this whole allowing a user to read root's history, but this i guess would be one of the more secure ways..

Of course.

carlocci /  $  sudo find -L /etc -group root -and -perm -020
/etc/fonts/conf.d/40-generic.conf
/etc/fonts/conf.d/20-lohit-gujarati.conf
/etc/fonts/conf.d/30-amt-aliases.conf

Which are broken links, maybe some broken package I will check later.
Same for /opt and /usr... damn I have a lot of broken links!

It's true you would have access to some /dev, which is ugly actually but since he asked to read root's bash_history...


And the script isn't even real time since you would have to exit the shell to update .bash_history.
You could write a simple script/alias which calls pacman and dump the parameters you used to, eg, /var/log/pacman_history

#!/bin/bash
echo pacman $* >> /var/tmp/pacman_history
/usr/bin/pacman $*

Simply place this "script" some place in your path with a higher priority over /usr/bin.
Check pacman_history file permissions, make it readable to everyone, or better

-rw-rw---- 1 root wheel  6671  28 feb 22:56 pacman_history

Then edit the conky script to read the last line of that file,

echo "last cmd - " `tail -n1 /var/tmp/pacman_history`

Last edited by carlocci (2008-02-28 22:01:18)

Offline

#19 2008-02-28 22:42:49

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 679
Website

Re: Pacman Info for Conky

@ carlocci

Thats much nicer and in real-time as you say smile

@ cucullus

As much as I would like to take credit tongue it's not my work, find it here

http://ohioloco.ubuntuforums.org/showth … p?t=666842

It's really finicky to get it set up right, but the results are worth it.

Offline

#20 2008-02-29 00:46:14

koch
Member
From: Germany
Registered: 2008-01-26
Posts: 369

Re: Pacman Info for Conky

first i have to say thanks to all.

i have thought about it while doing some work here at home and decided to drop the whole last-command-thing.
will have to undo the changes but...
just to be sure...
which are the default rights ( chmod...) for /root exactly?:/

arch is great. you learn a lot in short time.

Offline

#21 2008-02-29 12:43:17

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 679
Website

Re: Pacman Info for Conky

koch wrote:

first i have to say thanks to all.

i have thought about it while doing some work here at home and decided to drop the whole last-command-thing.
will have to undo the changes but...
just to be sure...
which are the default rights ( chmod...) for /root exactly?:/

arch is great. you learn a lot in short time.

chmod 750 /root

Offline

Board footer

Powered by FluxBB