LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-26-2016, 04:10 AM   #1
netpumber
Member
 
Registered: Sep 2007
Location: In My Box
Distribution: Arch Linux
Posts: 423

Rep: Reputation: 33
Firejailed programs check script


Hello.

I'm using firejail to run some apps like Chromium for example.

What I want to do now is to write a script that in a specific interval of time will check for example if all chromium processes are running through firejail. If this is not the case then it will inform me with a notify-send command.

So I'm wondering how can I achieve something like this and any idea will be thankful.
 
Old 05-26-2016, 05:44 AM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by netpumber View Post

What I want to do now is to write a script that in a specific interval of time will check for example if all chromium processes are running through firejail. If this is not the case then it will inform me with a notify-send command.

So I'm wondering how can I achieve something like this and any idea will be thankful.
Not that I have ever used firejail, but yes, this should be doable.
If you want your script to run at certain times, I would personally use either cron or an eternal loop with a sleep statement in the script, cron would be my first choice.

Using notify-send in a script is no problem as long as you don't run the script as root. The latter can be done (I actually do that in one of my scripts on my Arch box) but it requires a bit of extra work. As a normal user, you just:
Code:
notify-send "Hello"
In your script, that's it.

Best regards,
HMW
 
Old 05-27-2016, 06:42 AM   #3
netpumber
Member
 
Registered: Sep 2007
Location: In My Box
Distribution: Arch Linux
Posts: 423

Original Poster
Rep: Reputation: 33
Thank you very much for your answer but i was wondering on the part of the script that will check if the chromium's process runs through firejail.

For example i tried to implement that part of the script by checking if the parent pid of the chromium belongs to firejail process but for some reason that didn't work.
 
Old 05-27-2016, 07:28 AM   #4
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by netpumber View Post
Thank you very much for your answer but i was wondering on the part of the script that will check if the chromium's process runs through firejail.

For example i tried to implement that part of the script by checking if the parent pid of the chromium belongs to firejail process but for some reason that didn't work.
I've never used firejail, but why don't you share the part of your script that doesn't work?
 
Old 05-28-2016, 12:51 PM   #5
netpumber
Member
 
Registered: Sep 2007
Location: In My Box
Distribution: Arch Linux
Posts: 423

Original Poster
Rep: Reputation: 33
Finally i fixed the problem with the script and now it can print out if the chromium is firejailed or not.

Here is the code :

Code:
#!/bin/bash

# Get chromium's first pid
pid=$(ps -A | grep -m1 chromium | awk '{ print $1 }')
# Get its parent pid
ppid=$(ps -o ppid= -p $pid)
# Get its parent process name
pname=$(ps -p $ppid -o comm=)

if [ "$pname" = "firejail" ]; then
    notify-send -u low "firejail-check" "Chromium is firejailed"
else
    notify-send -u critival "firejail-check" "Chromium isn't firejailed"
fi
I'm wondering now, if there is any way to run this script only when a chromium process is starting.

Any idea?
 
Old 05-28-2016, 01:22 PM   #6
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Great!

Just a hint, instead of doing
Code:
pid=$(ps -A | grep -m1 chromium | awk '{ print $1 }')
You can do
Code:
pid=$(pidof chromium)
Saves a couple of pipes, but your version works just as well.
Also, there is a slight error in your 2nd notify, you wrote "critival" instead or critical, so it might not work as expected.

As far as only running this when chromium starts you could use cron, I would!

Good work!
HMW

Last edited by HMW; 05-28-2016 at 01:44 PM.
 
Old 05-29-2016, 03:22 AM   #7
netpumber
Member
 
Registered: Sep 2007
Location: In My Box
Distribution: Arch Linux
Posts: 423

Original Poster
Rep: Reputation: 33
Thank you very much for your notices

I also make some changes to the script and now ps returns a sorted list of chromium processes because i had a little problem with the previous version.

Here is the update :

Code:
 #!/bin/bash

# Get chromium's first pid
pid=$(ps -A --sort=start_time | grep -m1 chromium | awk '{ print $1 }')

if [ -n "$pid" ]; then

    # Get its parent pid
    ppid=$(ps -o ppid= -p $pid)
    # Get its parent process name
    pname=$(ps -p $ppid -o comm=)

    if [ "$pname" = "firejail" ]; then
        echo '<span foreground="#4285f4"></span>'
    else
        notify-send -u critical "firejail-check" "Chromium isn't firejailed"
        echo '<span foreground="#FF0000"> Chromium warning</span>'
    fi
fi
Actually I'm using i3 wm and i run it through i3blocks bar
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash script to check if file is present or not, check periodically every 30 mins Iyyappan Linux - Server 10 07-03-2013 05:19 AM
Script to check PID from file and check whether process is running or not rajkiran183 Linux - Newbie 5 10-19-2012 11:28 AM
How to check that my script can check if it has a specific range of charcters. shirlcurl20 Linux - Newbie 2 11-16-2010 11:15 PM
SaTaN please 3 programs to check bprasanth_20 Programming 9 10-20-2003 11:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration