SlideShare a Scribd company logo
inotify


Inotify is a framework inside Linux kernel which will notify filesystem
              events to subscribed userspace applications.

We will explore briefly about how we can use these notifications to
automate workflows in a production system (or in a home system)

                            By Mohan R
               Session at ILUGC meet on 2012.08.11
programming with inotify

●   #include <sys/inotify.h>

●inotify_init() to get file descriptor (in other terms, a pipeline from
kernel).

●inotify_add_watch() to get watch file descriptor for each directory
you want to listen for events.

●   inotify_rm_watch() to remove directories from watching

●   read() to get event data from kernel
iprocess


●A simple program which subscribes to inotify with set of directories
and then execute commands whenever it gets event data from
kernel.

● Capable of using your multi-core cpu with full advantage as it uses
threads.

●   Source code lives at github.
Iprocess in action

$ iprocess -d /work/ftp_downloads -m IN_CREATE,IN_MODIFY
“gzip [fullname] && mv [fullname].gz
/work/ftp_downloads_gzipped” -n 2

This above command will listen for changes in /work/ftp_downloads
directory, if a new file arrives to that directory, it will be automatically
compressed using gzip and moved to another directory called
/work/ftp_downloads_gzipped.

Above command can compress 2 files at a time using 2 of
machine's cpu cores.
Use Case
Requirement: I have a mobile with limited memory (1GB). I want my
favourite songs but dont want to give up my memory only for mp3
songs because I surf through my opera when I get bored and
sometime I download interesting things if I come across.

As per today's standard, one 320kbps mp3 song file of a tamil movie
will come around 10MB. By average, one tamil movie contains 5
songs. So, If I want 2 tamil movie songs into my mobile, I need to give
up 100MB.

There is a way to reduce size of mp3 files by reducing it's bitrate to
128kbps trading off it's quality for size. So, If I reduce 10MB file to
5MB, then I need to give up only 50MB.
is the killer for these kind of compression/conversion tasks. Some
bureaucracy happened and nowadays, major distros pack libav instead
of ffmpeg.
Contd..
I wrote a script called mobilecompress.sh which will take a mp3
song's filename, reduce its bitrate and produces an output with
given output filename. It uses avconv(ffmpeg) to reduce the bitrate.
Combining the power of iprocess with mobilecompress.sh, I'm
going to automate compression flow, Lets go to the command line,

$ iprocess -d /home/mohan/Music/ToConvert -m
IN_CREATE,IN_MODIFY
“/home/mohan/Development/scripts/mobilecompress.sh
[fullname] /home/mohan/Music/Converted/[name]”

Above command will convert any file arrives at ToConvert directory
and produces output in Converted directory

All I need to do is, download the mp3 files from Internet and put it
inside ToConvert directory, iprocess+mobilecompress.sh will take
care of reducing its size for my mobile.
Id3v2 and id3image
● Id3v2 is a standard to embed additional information to mp3 files
like composer, album, singers etc.,

●We can also embed Album posters directly into mp3 files. Music
players capable of reading id3v2 information can display that poster
whenever it plays that mp3 file.

●Id3lib is a open source c++ library which can operate on id3v2
data.

●Id3image is a program which can extract the poster image from
mp3 file or can embed new image into the mp3 file.

●   Source is currently lives inside github.
Id3v2 and id3image

$ id3image -i /home/mohan/Downloads/AvanIvan.jpg
/home/mohan/Music/YuvanHits/AvanIvan/DiaDiaDole.mp3

Above command will extract AvanIvan.jpg file from
DiaDiaDole.mp3.

$ id3image -l -i /home/mohan/Downloads/Billa2.jpg
/home/mohan/Music/Converted/Billa2/*

Above command will embed Billa2.img into all the files inside
Converted/Billa2 directory.
Finally..




Lets play the songs..
Question Time




Any Question???

More Related Content

What's hot

Linux
LinuxLinux
A brief history of system calls
A brief history of system callsA brief history of system calls
A brief history of system calls
Sysdig
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for Beginners
Davide Ciambelli
 
Presentation Linux Server setup Advance Networking
Presentation   Linux Server setup Advance NetworkingPresentation   Linux Server setup Advance Networking
Presentation Linux Server setup Advance Networking
Tariqul Islam Shohag
 
Compiling linux kernel and submit first patch
Compiling linux kernel and submit first patchCompiling linux kernel and submit first patch
Compiling linux kernel and submit first patch
Mayur Patil
 
Using filesystem capabilities with rsync
Using filesystem capabilities with rsyncUsing filesystem capabilities with rsync
Using filesystem capabilities with rsync
Hazel Smith
 
Unix tutorial-08
Unix tutorial-08Unix tutorial-08
Unix tutorial-08
kavitha_tala
 
Linux Commands - 3
Linux Commands - 3Linux Commands - 3
Linux Commands - 3Kanchilug
 
Linux day 1
Linux day 1Linux day 1
Linux day 1
sumairdotcom
 
Lightweight development (Lightning talk)
Lightweight development (Lightning talk)Lightweight development (Lightning talk)
Lightweight development (Lightning talk)
zroger
 
Linux : Booting and runlevels
Linux : Booting and runlevelsLinux : Booting and runlevels
Linux : Booting and runlevels
John Ombagi
 
How to Save, backup and restore IOS on Cisco router
How to Save, backup and restore IOS on Cisco routerHow to Save, backup and restore IOS on Cisco router
How to Save, backup and restore IOS on Cisco routertcpipguru
 
Linux
LinuxLinux
Linux Run Level
Linux Run LevelLinux Run Level
Linux Run Level
Gaurav Mishra
 
Gnome terminal basics
Gnome terminal basicsGnome terminal basics
Gnome terminal basics
Kamrul Hasan
 
Docker
DockerDocker
A journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service managementA journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service management
Lubomir Rintel
 
Linux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptLinux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell script
Kenny (netman)
 

What's hot (20)

Linux
LinuxLinux
Linux
 
A brief history of system calls
A brief history of system callsA brief history of system calls
A brief history of system calls
 
Unix
UnixUnix
Unix
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for Beginners
 
Presentation Linux Server setup Advance Networking
Presentation   Linux Server setup Advance NetworkingPresentation   Linux Server setup Advance Networking
Presentation Linux Server setup Advance Networking
 
Compiling linux kernel and submit first patch
Compiling linux kernel and submit first patchCompiling linux kernel and submit first patch
Compiling linux kernel and submit first patch
 
Linux monitoring
Linux monitoringLinux monitoring
Linux monitoring
 
Using filesystem capabilities with rsync
Using filesystem capabilities with rsyncUsing filesystem capabilities with rsync
Using filesystem capabilities with rsync
 
Unix tutorial-08
Unix tutorial-08Unix tutorial-08
Unix tutorial-08
 
Linux Commands - 3
Linux Commands - 3Linux Commands - 3
Linux Commands - 3
 
Linux day 1
Linux day 1Linux day 1
Linux day 1
 
Lightweight development (Lightning talk)
Lightweight development (Lightning talk)Lightweight development (Lightning talk)
Lightweight development (Lightning talk)
 
Linux : Booting and runlevels
Linux : Booting and runlevelsLinux : Booting and runlevels
Linux : Booting and runlevels
 
How to Save, backup and restore IOS on Cisco router
How to Save, backup and restore IOS on Cisco routerHow to Save, backup and restore IOS on Cisco router
How to Save, backup and restore IOS on Cisco router
 
Linux
LinuxLinux
Linux
 
Linux Run Level
Linux Run LevelLinux Run Level
Linux Run Level
 
Gnome terminal basics
Gnome terminal basicsGnome terminal basics
Gnome terminal basics
 
Docker
DockerDocker
Docker
 
A journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service managementA journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service management
 
Linux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptLinux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell script
 

Similar to inotify

Linux basic
Linux basicLinux basic
Linux basic
Pragyagupta37
 
Linux Cheat Sheet.pdf
Linux Cheat Sheet.pdfLinux Cheat Sheet.pdf
Linux Cheat Sheet.pdf
roschahacker
 
Linux kernel
Linux kernelLinux kernel
Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)
Amin Astaneh
 
Prizm Installation Guide
Prizm Installation GuidePrizm Installation Guide
Prizm Installation Guide
vjvarenya
 
Daemons
DaemonsDaemons
Daemons
christina555
 
Ppt
PptPpt
HowTo Install openMPI on Ubuntu
HowTo Install openMPI on UbuntuHowTo Install openMPI on Ubuntu
HowTo Install openMPI on Ubuntu
A Jorge Garcia
 
Audio and Video Streaming
Audio and Video StreamingAudio and Video Streaming
Audio and Video Streaming
Nyros Technologies
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
Robert Lujo
 
Software management in linux
Software management in linuxSoftware management in linux
Software management in linuxnejadmand
 
Bringing-it-all-together-overview-of-rpm-packaging-in-fedora
Bringing-it-all-together-overview-of-rpm-packaging-in-fedoraBringing-it-all-together-overview-of-rpm-packaging-in-fedora
Bringing-it-all-together-overview-of-rpm-packaging-in-fedora
Lalatendu Mohanty
 
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios CoreNrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
Nagios
 
NRPE - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core 4 and others.
NRPE - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core 4 and others.NRPE - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core 4 and others.
NRPE - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core 4 and others.
Marc Trimble
 

Similar to inotify (20)

Linux basic
Linux basicLinux basic
Linux basic
 
Linux Cheat Sheet.pdf
Linux Cheat Sheet.pdfLinux Cheat Sheet.pdf
Linux Cheat Sheet.pdf
 
Linux
LinuxLinux
Linux
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Linux
Linux Linux
Linux
 
Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)
 
Divya
DivyaDivya
Divya
 
Divya
DivyaDivya
Divya
 
Prizm Installation Guide
Prizm Installation GuidePrizm Installation Guide
Prizm Installation Guide
 
Daemons
DaemonsDaemons
Daemons
 
Ppt
PptPpt
Ppt
 
Nrpe
NrpeNrpe
Nrpe
 
HowTo Install openMPI on Ubuntu
HowTo Install openMPI on UbuntuHowTo Install openMPI on Ubuntu
HowTo Install openMPI on Ubuntu
 
Audio and Video Streaming
Audio and Video StreamingAudio and Video Streaming
Audio and Video Streaming
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
 
Software management in linux
Software management in linuxSoftware management in linux
Software management in linux
 
Bringing-it-all-together-overview-of-rpm-packaging-in-fedora
Bringing-it-all-together-overview-of-rpm-packaging-in-fedoraBringing-it-all-together-overview-of-rpm-packaging-in-fedora
Bringing-it-all-together-overview-of-rpm-packaging-in-fedora
 
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios CoreNrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
 
NRPE - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core 4 and others.
NRPE - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core 4 and others.NRPE - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core 4 and others.
NRPE - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core 4 and others.
 

Recently uploaded

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 

inotify

  • 1. inotify Inotify is a framework inside Linux kernel which will notify filesystem events to subscribed userspace applications. We will explore briefly about how we can use these notifications to automate workflows in a production system (or in a home system) By Mohan R Session at ILUGC meet on 2012.08.11
  • 2. programming with inotify ● #include <sys/inotify.h> ●inotify_init() to get file descriptor (in other terms, a pipeline from kernel). ●inotify_add_watch() to get watch file descriptor for each directory you want to listen for events. ● inotify_rm_watch() to remove directories from watching ● read() to get event data from kernel
  • 3. iprocess ●A simple program which subscribes to inotify with set of directories and then execute commands whenever it gets event data from kernel. ● Capable of using your multi-core cpu with full advantage as it uses threads. ● Source code lives at github.
  • 4. Iprocess in action $ iprocess -d /work/ftp_downloads -m IN_CREATE,IN_MODIFY “gzip [fullname] && mv [fullname].gz /work/ftp_downloads_gzipped” -n 2 This above command will listen for changes in /work/ftp_downloads directory, if a new file arrives to that directory, it will be automatically compressed using gzip and moved to another directory called /work/ftp_downloads_gzipped. Above command can compress 2 files at a time using 2 of machine's cpu cores.
  • 5. Use Case Requirement: I have a mobile with limited memory (1GB). I want my favourite songs but dont want to give up my memory only for mp3 songs because I surf through my opera when I get bored and sometime I download interesting things if I come across. As per today's standard, one 320kbps mp3 song file of a tamil movie will come around 10MB. By average, one tamil movie contains 5 songs. So, If I want 2 tamil movie songs into my mobile, I need to give up 100MB. There is a way to reduce size of mp3 files by reducing it's bitrate to 128kbps trading off it's quality for size. So, If I reduce 10MB file to 5MB, then I need to give up only 50MB. is the killer for these kind of compression/conversion tasks. Some bureaucracy happened and nowadays, major distros pack libav instead of ffmpeg.
  • 6. Contd.. I wrote a script called mobilecompress.sh which will take a mp3 song's filename, reduce its bitrate and produces an output with given output filename. It uses avconv(ffmpeg) to reduce the bitrate. Combining the power of iprocess with mobilecompress.sh, I'm going to automate compression flow, Lets go to the command line, $ iprocess -d /home/mohan/Music/ToConvert -m IN_CREATE,IN_MODIFY “/home/mohan/Development/scripts/mobilecompress.sh [fullname] /home/mohan/Music/Converted/[name]” Above command will convert any file arrives at ToConvert directory and produces output in Converted directory All I need to do is, download the mp3 files from Internet and put it inside ToConvert directory, iprocess+mobilecompress.sh will take care of reducing its size for my mobile.
  • 7. Id3v2 and id3image ● Id3v2 is a standard to embed additional information to mp3 files like composer, album, singers etc., ●We can also embed Album posters directly into mp3 files. Music players capable of reading id3v2 information can display that poster whenever it plays that mp3 file. ●Id3lib is a open source c++ library which can operate on id3v2 data. ●Id3image is a program which can extract the poster image from mp3 file or can embed new image into the mp3 file. ● Source is currently lives inside github.
  • 8. Id3v2 and id3image $ id3image -i /home/mohan/Downloads/AvanIvan.jpg /home/mohan/Music/YuvanHits/AvanIvan/DiaDiaDole.mp3 Above command will extract AvanIvan.jpg file from DiaDiaDole.mp3. $ id3image -l -i /home/mohan/Downloads/Billa2.jpg /home/mohan/Music/Converted/Billa2/* Above command will embed Billa2.img into all the files inside Converted/Billa2 directory.