LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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-17-2012, 04:52 PM   #1
rey
Member
 
Registered: Sep 2011
Posts: 49

Rep: Reputation: Disabled
echo and cat : write error: Invalid argument


hello
i'm trying to write to this file
Code:
/proc/net/xt_recent/recent_blocked
however my commands have failed even executed as root:

Code:
cat $DIR/recents > /proc/net/xt_recent/recent_blocked
cat: write error: Invalid argument
that file stores some blocked ip addresses for iptables,
i need to know how to write to this file to make my
scripts work, i have searched a lot without clear results

thanks for your help
 
Old 05-17-2012, 05:20 PM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
cat is for reading the values in the /proc file system.

To write, you shoud use echo:
Code:
echo $DIR/recents > /proc/net/xt_recent/recent_blocked
Of course, you can write only one value at a time.

And keep in mind that /proc store only one value in each "file", thus $DIR/recents should contain only one value.

Last edited by Didier Spaier; 05-17-2012 at 05:23 PM.
 
Old 05-17-2012, 05:26 PM   #3
rey
Member
 
Registered: Sep 2011
Posts: 49

Original Poster
Rep: Reputation: Disabled
sorry, if you echo a filename you get the same file name, not the contents
cat is for reading the file contents!!!

in your example you get the very same file path

any other ideas?
 
Old 05-17-2012, 05:36 PM   #4
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by rey View Post
sorry, if you echo a filename you get the same file name, not the contents
cat is for reading the file contents!!!
That's right, but on the other hand you can't redirect the output of cat to /proc.

EDIT Out of curiosity, why use /proc to store the blocked ip addresses?

Last edited by Didier Spaier; 05-17-2012 at 05:40 PM.
 
Old 05-17-2012, 05:47 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by rey View Post
hello
i'm trying to write to this file
Code:
/proc/net/xt_recent/recent_blocked
however my commands have failed even executed as root:

Code:
cat $DIR/recents > /proc/net/xt_recent/recent_blocked
cat: write error: Invalid argument
that file stores some blocked ip addresses for iptables,
i need to know how to write to this file to make my
scripts work, i have searched a lot without clear results

thanks for your help

Use iptables to write iptables rules/stats.

proc, for the most part, is read-only; it's a view into
the running kernel, not a saloon door.


Cheers,
Tink
 
Old 05-17-2012, 05:57 PM   #6
rey
Member
 
Registered: Sep 2011
Posts: 49

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Didier Spaier View Post
EDIT Out of curiosity, why use /proc to store the blocked ip addresses?

that's how iptables work, it has a 'recent' module and the manual says that you can add
ip addresses to block them automatically, without adding extra rules


Quote:
/proc/net/ipt_recent/* are the current lists of addresses and information about each entry of each list.
Each file in /proc/net/ipt_recent/ can be read from to see the current list or written two using the following commands to modify the list:

echo xx.xx.xx.xx > /proc/net/ipt_recent/DEFAULT
to Add to the DEFAULT list
echo -xx.xx.xx.xx > /proc/net/ipt_recent/DEFAULT
to Remove from the DEFAULT list

neither works for me, i'm running ubuntu 10.04 lucid
i wonder why it seems to work for other setups

thanks for your comments

Last edited by rey; 05-17-2012 at 05:59 PM.
 
  


Reply



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
VIDIOC_S_FMT error 22, Invalid argument boidi Linux - Software 8 07-31-2017 01:00 PM
nm-openvpn write to TUN/TAP : Invalid argument (code=22) jonaskellens Linux - Newbie 0 08-24-2009 03:49 AM
message sending failed : Error[22 ] invalid argument .....but each and every argument rakeshranjanjha Linux - Software 2 01-07-2008 11:22 PM
Tar error: cannot write: invalid argument kaplan71 Red Hat 3 11-02-2006 10:37 AM
Invalid Argument Error ahmedb72 Red Hat 1 02-25-2006 07:52 AM

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

All times are GMT -5. The time now is 02:23 AM.

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