Skip to main content

Posts

Showing posts with the label bash

ocaml list directory

Goals The goal with this very simple script is to list a directory and find who is a directory, who is a file. The secondary goal (for me) is to run it as a script. I dont want to compile it but just run it as I would run bash, Perl or PHP script. The code This is how I do it : #!/ usr / bin / ocamlrun / usr / bin / ocaml #load "unix.cma" ;; print_string "Loaded Unix\n" ;; let tmp_dir = Unix .opendir "/tmp" ;; print_string "opened /tmp\n" ;; (* let tmp_dir_files = Unix.readdir tmp_dir;; *) let print_type a_thing = match Sys .is_directory ( "/tmp/" ^ a_thing ) with | true -> print_string ( "Dir:\t" ^ a_thing ^ "/\n" ) | false -> print_string ( "File:\t" ^ a_thing ^ "\n" );; print_type ( Unix .readdir tmp_dir );; print_type ( Unix .readdir tmp_dir );; print_type ( Unix .readdir tmp_dir );; print_type ( Unix .readdir tm...

sudo redirect to a file

When wanting to append some string to a file using sudo [mihamina@dell-f17 ~]$ pdsh  'echo "sshd:LOCAL,41.190.237.66,41.188.46.121" | sudo tee  /etc/hosts.allow' hosting: sshd:LOCAL,41.190.237.66,41.188.46.121 filer: sshd:LOCAL,41.190.237.66,41.188.46.121 recette53: sshd:LOCAL,41.190.237.66,41.188.46.121 prod53: sshd:LOCAL,41.190.237.66,41.188.46.121 recette52: sshd:LOCAL,41.190.237.66,41.188.46.121 prod52: sshd:LOCAL,41.190.237.66,41.188.46.121 And it gives: [mihamina@dell-f17 ~]$ pdsh  'sudo grep sshd /etc/hosts.allow' recette53: sshd:LOCAL,41.190.237.66,41.188.46.121 prod53: sshd:LOCAL,41.190.237.66,41.188.46.121 filer: sshd:LOCAL,41.190.237.66,41.188.46.121 hosting: sshd:LOCAL,41.190.237.66,41.188.46.121 recette52: sshd:LOCAL,41.190.237.66,41.188.46.121 prod52: sshd:LOCAL,41.190.237.66,41.188.46.121