Discussion:
Linux files question and very of gambas topic
(too old to reply)
ron
2004-03-13 08:50:41 UTC
Permalink
Hello,

Is there a way to find out to log and see witch files/directories
are requested by a program?
I think something like FileMon under windows.
This is handy to find out where the files are expected to be
and are existing or not.
This is done in realtime so you can track these errors.

i.e. A program wants a myprogram.png file and it does not exist.
The KDE controlcenter want some icons I do not have so the are visual
missing. I assume the program is opening the file and get a error.
If I can log/see this file request I can maybe use an appropriate icon.

If it can be done with a already existing program what is the name of it?

2 question.
I want 2 or more files add together. In good old dos it was
copy file1 + file2 + file3 sumfile
or
copy file1 sumfile
type file2 > sumfile
type file2 > sumfile
or
append file3 sumfile
I need to append several binairy files together but can't find a simple CLI
command to do that.
As far I found it can't be done with cp or dd, but what else exists.

Maybe gambas can do it but I feel so stupid I can't solve this.


Ron

--
NASA spend over 1 million dollar for astronauts to shave without dust.
The garbage man says "Let them use a raiser blade with shaving cream"
Laurent Godard
2004-03-13 09:02:25 UTC
Permalink
Hi ron,
Post by ron
I need to append several binairy files together but can't find a simple CLI
command to do that.
did you try, under shell

cat file1 file2 file3 > targetfile

inside gambas, i would try
open a target for append as binary (or equivalent)
loop over source files
open as read binary
read
write target

HTH

laurent
--
-----------------------------------------
Laurent Godard - Conseil et Développement
06 85 33 27 90 - ***@wanadoo.fr
-----------------------------------------
ron
2004-03-13 14:57:57 UTC
Permalink
Post by Laurent Godard
Hi ron,
Post by ron
I need to append several binairy files together but can't find a simple
CLI command to do that.
did you try, under shell
cat file1 file2 file3 > targetfile
inside gambas, i would try
open a target for append as binary (or equivalent)
loop over source files
open as read binary
read
write target
HTH
laurent
I new it could be simple, You have only to know how.

Well the cat file1 file2 file3 > target did it in the test.
I did not see extra or missing bytes at the point the files where append.

The gambas way is nice but it should run as a cron task and then the cat way
is more easy.

Ok so I can write a script ????

copy a working script as example with same functionality
addfiles.sh with permission all set rwxrwxrwx

#! /bin/sh
# in the above line do I need the space or not ?????????
cd /data/ham/amsat/received
myfiles=$(ls *.bin)

for myfile in $myfiles; do
cat /data/ham/amsat/received/$myfile > /data/ham/amsat/screen/rpack.bin
#rm /data/ham/amsat/received/$myfile
done
cd -

The result is
bash: ./append.sh: /bin/sh: bad interpreter: Permission denied

I'm feeling so stupid ;(

Thanks Ron.
Benoit Minisini
2004-03-13 15:04:02 UTC
Permalink
Post by ron
Post by Laurent Godard
Hi ron,
Post by ron
I need to append several binairy files together but can't find a simple
CLI command to do that.
did you try, under shell
cat file1 file2 file3 > targetfile
inside gambas, i would try
open a target for append as binary (or equivalent)
loop over source files
open as read binary
read
write target
HTH
laurent
I new it could be simple, You have only to know how.
Well the cat file1 file2 file3 > target did it in the test.
I did not see extra or missing bytes at the point the files where append.
The gambas way is nice but it should run as a cron task and then the cat
way is more easy.
Ok so I can write a script ????
copy a working script as example with same functionality
addfiles.sh with permission all set rwxrwxrwx
#! /bin/sh
# in the above line do I need the space or not ?????????
cd /data/ham/amsat/received
myfiles=$(ls *.bin)
for myfile in $myfiles; do
cat /data/ham/amsat/received/$myfile > /data/ham/amsat/screen/rpack.bin
#rm /data/ham/amsat/received/$myfile
done
cd -
The result is
bash: ./append.sh: /bin/sh: bad interpreter: Permission denied
I'm feeling so stupid ;(
Thanks Ron.
Did you try #!/bin/sh without a space ?

Otherwise, you can use a gambas executable in your crontab. After all, gambas
executable are exactly shell scripts, except that you have #!/bin/gbx in the
beginning of the file instead of #!/bin/sh.

Regards,
--
Benoit Minisini
mailto:***@users.sourceforge.net
ron
2004-03-13 18:09:33 UTC
Permalink
Post by Benoit Minisini
Post by ron
I'm feeling so stupid ;(
Thanks Ron.
Did you try #!/bin/sh without a space ?
Otherwise, you can use a gambas executable in your crontab. After all,
gambas executable are exactly shell scripts, except that you have
#!/bin/gbx in the beginning of the file instead of #!/bin/sh.
Regards,
Of course, I am stupid but not so. :)
Have seen it in both ways.
I know that it was your intention it could be used this way and that is
a pleasure but for this simple task may be a bit overload.
For bigger I will try it because the basic language is at the moment better
then mine acknowledge of bash etc.

Brings me to another case. I have seen gambas start also that way.
from the CLI is works, even with mc does it work, but not in Konqueror.

I have made once the mime type stuff and was able to start with gbx.
Also the Type of the file had the right description and the right icon.
Click in konqueror did work to. Will make it again.

Thanks Ron
Laurent Godard
2004-03-13 15:32:38 UTC
Permalink
Hi ron,
Post by ron
copy a working script as example with same functionality
addfiles.sh with permission all set rwxrwxrwx
#! /bin/sh
# in the above line do I need the space or not ?????????
cd /data/ham/amsat/received
myfiles=$(ls *.bin)
for myfile in $myfiles; do
cat /data/ham/amsat/received/$myfile > /data/ham/amsat/screen/rpack.bin
#rm /data/ham/amsat/received/$myfile
done
cd -
sorry, i'm a totally beginner under linux

why writing a loop ?

I would have replace the loop by in single statement like
cat /data/ham/amsat/received/*.bin > /data/ham/amsat/screen/rpack.bin

do i miss something ?

Laurent
--
-----------------------------------------
Laurent Godard - Conseil et Développement
06 85 33 27 90 - ***@wanadoo.fr
-----------------------------------------
ron
2004-03-13 18:46:27 UTC
Permalink
Post by Laurent Godard
Hi ron,
why writing a loop ?
I would have replace the loop by in single statement like
cat /data/ham/amsat/received/*.bin > /data/ham/amsat/screen/rpack.bin
do i miss something ?
Laurent
I'm not shure but in my code the orginal must be deleted
and the amount of files is unknown.

At first view I say here is every file typed/copied to rpack.bin
and only the last one is in rpack.bin after finish instead appended.

For me it is already strange there is one '>' in this 2'th example, in dos the
destination is replaced. Should it not be '>>' ?
I did a try and it look to work as you suggested with one '>'.

With one rm *.bin it is then cleaned but in feature there must be done a few
things with every file before the add is done so a loop is better at the
moment.

My question what can be wrong for the error message
bash: .addfiles.sh: /bin/sh: bad interpreter: Permission denied

I'm happy with this solutions given. Slowly I will learn working with bash.

Thanks very much
Ron.
Laurent Godard
2004-03-13 19:44:54 UTC
Permalink
Hi ron,

concerning bash
I don't know if it helps but you may have a look at

http://en.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

HTH

Laurent
--
-----------------------------------------
Laurent Godard - Conseil et Développement
06 85 33 27 90 - ***@wanadoo.fr
-----------------------------------------
ron
2004-03-14 08:42:58 UTC
Permalink
Post by Laurent Godard
Hi ron,
concerning bash
I don't know if it helps but you may have a look at
http://en.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
HTH
Laurent
Hi Laurent

Thats a nice little compact and not to much info. I can see the light.
I do have a book. Looks also great but is also a bit to overwhelming.
It is in my favourite list now.

But here I can't a hint about the permission denied.
I can't execute the script.

Ron
Laurent Godard
2004-03-15 07:04:01 UTC
Permalink
Hi Ron,
Post by ron
The result is
bash: ./append.sh: /bin/sh: bad interpreter: Permission denied
I don't know if tyour problem is solved, but did you check the
permisions of your file ? Is it executable with the current user
You may look at chmod fonction to make it executable

chmod 777 ./append.sh

As i'm a totally bneginner in unix environement, i may be wrong, though

Laurent
--
-----------------------------------------
Laurent Godard - Conseil et Développement
06 85 33 27 90 - ***@wanadoo.fr
-----------------------------------------
Rob
2004-03-15 13:34:15 UTC
Permalink
Post by Laurent Godard
chmod 777 ./append.sh
As i'm a totally bneginner in unix environement, i may be
wrong, though
Here's a free lesson, then :) Don't go "chmod 777" unless you
know you absolutely have to, especially if the file is owned by
root. That lets any user on your machine alter that file, and
while you may think of your machine as being a single-user box,
if there were some previously unknown vulnerability in apache or
a mail server or xinetd or samba or etc., the exploiter would
have a place to put further exploit code in hopes of gaining
root access.

chmod a+x will accomplish what you meant to do, should be a
little simpler for newbies to understand (add eXecute permission
for All) and doesn't open the file up to the world for writing.

Rob
Laurent Godard
2004-03-15 14:16:14 UTC
Permalink
HI Rob,
Post by Rob
Here's a free lesson, then :)
Thanks a lot :)
I'll remember your clear lesson

Laurent
--
-----------------------------------------
Laurent Godard - Conseil et Développement
06 85 33 27 90 - ***@wanadoo.fr
-----------------------------------------
ron
2004-03-15 21:47:13 UTC
Permalink
Post by Rob
Post by Laurent Godard
chmod 777 ./append.sh
As i'm a totally bneginner in unix environement, i may be
wrong, though
Here's a free lesson, then :) Don't go "chmod 777" unless you
know you absolutely have to, especially if the file is owned by
root. That lets any user on your machine alter that file, and
while you may think of your machine as being a single-user box,
if there were some previously unknown vulnerability in apache or
a mail server or xinetd or samba or etc., the exploiter would
have a place to put further exploit code in hopes of gaining
root access.
chmod a+x will accomplish what you meant to do, should be a
little simpler for newbies to understand (add eXecute permission
for All) and doesn't open the file up to the world for writing.
Rob
This is the same as chmod 666 file_to_set ?

I was so stuipd to set the /data3 (partition) with noexecin fstab to protect
this but that should be ro,exec in this case. See other mail I just send
away.

btw. this was/is the reason the wiki did not work, it was on the same drive!

Ron
Rob
2004-03-15 22:59:17 UTC
Permalink
Post by ron
Post by Rob
chmod a+x will accomplish what you meant to do, should be a
This is the same as chmod 666 file_to_set ?
No, quite different. chmod 666 filename blows away all the
permissions on the file, and replaces them with this: rw-rw-rw-
meaning it's more like a-x. But not the same, because a+x and
a-x only touch the x bit, leaving r and w as they were.

chmod seems like magic to a lot of people, so here's a nutshell
explanation of the numeric vs. the symbolic modes of chmod:

You have three types of user (user, group and other) and three
types of permission (read, write, and x for execute.) There are
other kinds of permission but forget about those for now. You
can add or remove permissions by using the first letter of the
type of user and the first letter of the type of permission,
with a plus or minus:

o-r turns off read permission for others.
ug+x turns on execute permission for everyone BUT others.
ugo+rwx is equivalent to chmod 777 filename.

That 777 thing is the numeric mode of chmod, and each digit
refers to a set of permissions: first digit being user, second
being group, third being other. You make the digits by adding
together the read, write and execute bits like so: read is 4,
write is 2, and execute is 1. It's called an "octal number"
because each digit can only be 0 through 7, but just thinking of
it as three separate digits jammed together and your head will
hurt less.

However, if you use the numeric mode, it will always get rid of
whatever permissions a file has and replace them with those
specified by your number. Like so:

a file that's rw-rw-rw- (666) and you set it to 700 becomes:
rwx------.
a file that's rw------- (400) and you make it 777 becomes:
rwxrwxrwx.
a file that's rwxr-xr-x (755, what you would typically want a
shell script or gambas executable to be) and you make it 000
becomes ---------. Oops! Now you can't write to it until you
chmod it again.

People who have a tough time wrapping their brains around the
octal permissions should just avoid them and use the symbolic
ones, and even more advanced users will use the symbolic modes
when, for example, we want to make all the directories in a tree
executable but none of the files (chmod -R a+X dirname.)

Rob
ron
2004-03-16 00:37:48 UTC
Permalink
Oeps. This was a nice explaination.
Now i understand why KDE 3.2 has a different property sheeft for the
permisions.
I think they do it now with the symbolic way instead the nummeric way in 3.14
and before.

Thanks Ron

ron
2004-03-15 21:36:32 UTC
Permalink
Post by Laurent Godard
Hi Ron,
Post by ron
The result is
bash: ./append.sh: /bin/sh: bad interpreter: Permission denied
I don't know if tyour problem is solved, but did you check the
permisions of your file ? Is it executable with the current user
You may look at chmod fonction to make it executable
chmod 777 ./append.sh
As i'm a totally bneginner in unix environement, i may be wrong, though
Laurent
Hi Laurent,

Yes I did set all the permissions as rwxrwxrwx and did it as root to be shure
I have had it once before in another script, it disapeared so the reason is
unknown, for a cron job and it worked.

It happens even with two lines, the #!/bin/sh and a # do i work line.

For other newbies:
Make a script named 'mydir' to show a directory in my home directory

#!/bin/bash
ls /

chmod 777 ./mydir
Try and it runs ok
move it to / and try, ok
move it to /tmp try, ok
move it to /data2 try, bad
Puzzling what is wrong???

And then I get the light, my data1 ... 4 are mounted partitions !
Open fstab and see
/dev/hda1 /data1 reiserfs auto,user,rw 0 0
/dev/hda3 /data2 auto auto,user,rw 0 0
/dev/hda7 /data3 reiserfs auto,user,rw 0 1
/dev/hda8 /data4 reiserfs auto,user,rw 0 0
As i'm right this tells me what is avialable on my system

Open mtab and see
/dev/hda1 /data1 reiserfs rw,noexec,nosuid,nodev 0 0
/devi/hda3 /data2 ext2 rw,noexec,nosuid,nodev 0 0
/dev/hda7 /data3 reiserfs rw,noexec,nosuid,nodev 0 0
/dev/hda8 /data4 reiserfs rw,noexec,nosuid,nodev 0 0

Aha 'noexec', that should be the problem.
umount not working

# umount -f /data2
umount2: Device or resource busy
umount: /dev/hda3: not mounted
umount: /data2: Illegal seek

# mount
/dev/hda1 on /data1 type reiserfs (rw,noexec,nosuid,nodev)
/dev/hda3 on /data2 type ext2 (rw,noexec,nosuid,nodev)
/dev/hda7 on /data3 type reiserfs (rw,noexec,nosuid,nodev)
/dev/hda8 on /data4 type reiserfs (rw,noexec,nosuid,nodev)

How do I remount /data2, the mount /data2 -remount, not working
mount /data2 -o exec, not working

I wil survive Ron
Benoit Minisini
2004-03-13 13:57:29 UTC
Permalink
Post by ron
Hello,
Is there a way to find out to log and see witch files/directories
are requested by a program?
I think something like FileMon under windows.
This is handy to find out where the files are expected to be
and are existing or not.
This is done in realtime so you can track these errors.
i.e. A program wants a myprogram.png file and it does not exist.
The KDE controlcenter want some icons I do not have so the are visual
missing. I assume the program is opening the file and get a error.
If I can log/see this file request I can maybe use an appropriate icon.
If it can be done with a already existing program what is the name of it?
You can try this, for example, to catch all files opened by the IDE.

$ cd ~/gambas/app/gambas
$ strace gbx 2&> strace.out
$ cat strace.out | grep "open("

With a better use of grep, you can be more accurate.

Regards,
--
Benoit Minisini
mailto:***@users.sourceforge.net
ron
2004-03-13 16:25:51 UTC
Permalink
Post by Benoit Minisini
Post by ron
Hello,
Is there a way to find out to log and see witch files/directories
are requested by a program?
I think something like FileMon under windows.
This is handy to find out where the files are expected to be
and are existing or not.
This is done in realtime so you can track these errors.
i.e. A program wants a myprogram.png file and it does not exist.
The KDE controlcenter want some icons I do not have so the are visual
missing. I assume the program is opening the file and get a error.
If I can log/see this file request I can maybe use an appropriate icon.
If it can be done with a already existing program what is the name of it?
You can try this, for example, to catch all files opened by the IDE.
$ cd ~/gambas/app/gambas
$ strace gbx 2&> strace.out
$ cat strace.out | grep "open("
With a better use of grep, you can be more accurate.
Regards,
It was not exactly to check the gambas IDE but playing with it on Kcontrol.

And just what I expected is true, SuSE makes a mess. KDE default is English.
I found Kcontrol with missing help trys to find in 'en_US' witch is unknown by
KDE after 3.1.4 and up
strace is in the way I wish, must play more with it

Tanks Ron
Continue reading on narkive:
Loading...