Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Execute a script once a file uploaded to directory Post 303045595 by Abu Rayane on Thursday 2nd of April 2020 05:44:45 PM
Old 04-02-2020
Here you go
Code:
#!/bin/sh

# Some vars here

# Dangerous files, extensions and shells
SHELLDETECT=$( find /home/uvid/www/Uploads/ -type f \( -iname "1.*" -o -iname "*eicar*" -o -iname "*.php" -o -iname "*.pl" -o -iname "*.txt" -o -iname "*.py" -o -iname "*.c" -o -iname "*.deb" -o -iname "*.zip" -o -iname "*.tar" -o -iname "*.gz" -o -iname "*.tar.gz" -o -iname "*.js" -o -iname "*.vbs" -o -iname "*.exe" -o -iname "*.asp" -o -iname "*.jsp" -o -iname "*.cgi" -o -iname "c100*" -o -iname "c99*" -o -iname "cmd*" -o -iname "webadmin*" -o -iname "r57*" -o -iname "*shell*" -o -iname "*angel*" -o -iname "*b374k*" -o -iname "*bv7binary*" -o -iname "*webroot*" -o -iname "*kacak*" -o -iname "*symlink*" -o -iname "*h4cker*" -o -iname "*gazashell*" -o -iname "*locus7shell*" -o -iname "*syrianshell*" -o -iname "*injection*" -o -iname "*cyberwarrior*" -o -iname "*ernebypass*" -o -iname "*g6shell*" -o -iname "*pouyaserver*" -o -iname "*saudishell*" -o -iname "*simattacker*" -o -iname "*sosyeteshell*" -o -iname "*tryagshell*" -o -iname "*uploadshell*" -o -iname "*wsoshell*" -o -iname "*weevely*" -o -iname "*zehir4shell*" -o -iname "*lostdcshell*" -o -iname "*commandshell*" -o -iname "*mailershell*" -o -iname "*cwshell*" -o -iname "*iranshell*" -o -iname "*indishell*" -o -iname "**g6sshell" -o -iname "*sqlshell*" -o -iname "*simshell*" -o -iname "*tryagshell*" -o -iname "*zehirshell*" -o -iname "*unknown*" -o -iname "*k2ll33d*" -o -iname "*b1n4ry*" \) )

if [[ $? == "0" ]]
then
echo "$SHELLDETECT" | mail -s "Shell bad extensions $TODAY" "$EMAIL"
fi


# Find large strings, more than 100 chars
largeStrings=$( find /home/immo/uvid/Uploads/ -type f -exec grep -Eq '.{100}' {} \; -exec ls -l {} + )

if [[ $? == "0" ]]
then
echo "$largeStrings" | mail -s "Large strings $TODAY" "$EMAIL"
fi


# Find files that was modified or created in last 24 hours
# -1 the last 24 hours
# -0.5 the last 12 hours
# -0.25 the last 6 hours
# +3 more than three days
# 0 Files modified between now and 1 day ago
     # (i.e., within the past 24 hours)
# 1 Files modified between 24 and 48 hours ago
# +1 Files modified more than 48 hours ago
modifFiles=$( find '/home/immo/uvid/Uploads/' -mtime 0 -ls )

if [[ $? == "0" ]]
then    
	echo "$modifFiles" | mail -s "Modified files $TODAY" "$EMAIL"
fi


Last edited by Abu Rayane; 04-02-2020 at 07:33 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to make sure a file is uploaded in its entirety

Hi, I have a client who uploads files to my FTP server on a regular basis. Instead of checking the server all the time, I wrote a script that e-mail me to let me know that there is a new file and attaches is it in the e-mail (they're all small compressed archives). The potential issue with the... (4 Replies)
Discussion started by: ph0enix
4 Replies

2. Shell Programming and Scripting

How to execute script on files in another directory?

Hi Guys, Is there any way I can execute my bash script on files in a different folder than what the script is in? Here is an excerpt of my script: #!/usr/bin/bash input_path="/cygdrive/c/files" output_path="/cygdrive/c/files/data" #script uses files from /cygdrive/c/files directory,... (1 Reply)
Discussion started by: npatwardhan
1 Replies

3. Shell Programming and Scripting

Execute unix shell script to text file using the script

Hi all, I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script? Thanks i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
Discussion started by: mastercar
4 Replies

4. Shell Programming and Scripting

Not to execute any graph if the file in a directory is zero bytes

How to code shell script to know if the file in a dirctory is empty i.e., zero byte then not to execute any graph.Please help on this thanks in advance. ---------- Post updated at 08:18 AM ---------- Previous update was at 08:14 AM ---------- I know if clause wil help.my question is how to... (7 Replies)
Discussion started by: vamsi86
7 Replies

5. UNIX for Dummies Questions & Answers

File uploaded via FTP not visible from Command Line

I am using VSFTPD on amazon web services and have a remote service that uploads files to server via FTP. The files comes through fine and when I log in via FTP client I see them. The problem is the files are supposed to be moved once uploaded but the files are not visible via command line thus the... (2 Replies)
Discussion started by: theman0684
2 Replies

6. Shell Programming and Scripting

How to execute korn shell script from different directory

Guy's , I need to run korn shell script from different directory, usually I run the script using ./details.ksh in the same directory but now I need to run the file and process details using awk code. Now I am running the script this way but with no luck Directory = home/users/work ... (3 Replies)
Discussion started by: James_Owen
3 Replies

7. UNIX for Dummies Questions & Answers

Execute a command in different directory through Unix Script

Hi Gurus, I have the below requirement, Execute an unix script which will pick the latest file from the archive directory and do a grep (on multiple patterns) on that file. processingDir="/usr/apps/irdc/informatica/spsf_sales/TgtFiles/ARCHIVE" filename = 'ls Check* | sort -n -k 2 |... (6 Replies)
Discussion started by: diva_thilak
6 Replies

8. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

9. Red Hat

Chroot: cannot execute /bin/sh: No such file or directory

Hi Expert, I'm having grub problem here: grub> root (hd0,0): Filesystem type is ext2 grub> setup Error 11 : Unrecognized Device String I try install boot loader follow the instruction from 26.2. Booting into Rescue Mode It says : select Continue, it attempts to mount your file... (4 Replies)
Discussion started by: justbow
4 Replies

10. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies
funopen(3)							SAORD Documentation							funopen(3)

NAME
FunOpen - open a Funtools data file SYNOPSIS
#include <funtools.h> Fun FunOpen(char *name, char *mode, Fun ref); DESCRIPTION
The FunOpen() routine opens a Funtools data file for reading or appending, or creates a new FITS file for writing. The name argument speci- fies the name of the Funtools data file to open. You can use IRAF-style bracket notation to specify Funtools Files, Extensions, and Fil- ters. A separate call should be made each time a different FITS extension is accessed: Fun fun; char *iname; ... if( !(fun = FunOpen(iname, "r", NULL)) ){ fprintf(stderr, "could not FunOpen input file: %s ", iname); exit(1); } If mode is "r", the file is opened for reading, and processing is set up to begin at the specified extension. For reading, name can be stdin, in which case the standard input is read. If mode is "w", the file is created if it does not exist, or opened and truncated for writing if it does exist. Processing starts at the beginning of the file. The name can be stdout, in which case the standard output is readied for processing. If mode is "a", the file is created if it does not exist, or opened if it does exist. Processing starts at the end of the file. The name can be stdout, in which case the standard output is readied for processing. When a Funtools file is opened for writing or appending, a previously opened Funtools reference handle can be specified as the third argu- ment. This handle typically is associated with the input Funtools file that will be used to generate the data for the output data. When a reference file is specified in this way, the output file will inherit the (extension) header parameters from the input file: Fun fun, fun2; ... /* open input file */ if( !(fun = FunOpen(argv[1], "r", NULL)) ) gerror(stderr, "could not FunOpen input file: %s ", argv[1]); /* open the output FITS image, inheriting params from input */ if( !(fun2 = FunOpen(argv[2], "w", fun)) ) gerror(stderr, "could not FunOpen output file: %s ", argv[2]); Thus, in the above example, the output FITS binary table file will inherit all of the parameters associated with the input binary table extension. A file opened for writing with a Funtools reference handle also inherits the selected columns (i.e. those columns chosen for processing using the FunColumnSelect() routine) from the reference file as its default columns. This makes it easy to open an output file in such a way that the columns written to the output file are the same as the columns read in the input file. Of course, column selection can easily be tailored using the FunColumnSelect() routine. In particular, it is easy to merge user-defined columns with the input columns to gener- ate a new file. See the evmerge for a complete example. In addition, when a Funtools reference handle is supplied in a FunOpen() call, it is possible also to specify that all other extensions from the reference file (other than the input extension being processed) should be copied from the reference file to the output file. This is useful, for example, in a case where you are processing a FITS binary table or image and you want to copy all of the other extensions to the output file as well. Copy of other extensions is controlled by adding a "C" or "c" to the mode string of the FunOpen() call of the input reference file. If "C" is specified, then other extensions are always copied (i.e., copy is forced by the application). If "c" is used, then other extensions are copied if the user requests copying by adding a plus sign "+" to the extension name in the bracket specifi- cation. For example, the funtable program utilizes "c" mode, giving users the option of copying all other extensions: /* open input file -- allow user copy of other extensions */ if( !(fun = FunOpen(argv[1], "rc", NULL)) ) gerror(stderr, "could not FunOpen input file: %s ", argv[1]); /* open the output FITS image, inheriting params from input */ if( !(fun2 = FunOpen(argv[2], "w", fun)) ) gerror(stderr, "could not FunOpen output file: %s ", argv[2]); Thus, funtable supports either of these command lines: # copy only the EVENTS extension csh> funtable "test.ev[EVENTS,circle(512,512,10)]" foo.ev # copy ALL extensions csh> funtable "test.ev[EVENTS+,circle(512,512,10)]" foo.ev Use of a Funtools reference handle implies that the input file is opened before the output file. However, it is important to note that if copy mode ("c" or "C") is specified for the input file, the actual input file open is delayed until just after the output file is opened, since the copy of prior extensions to the output file takes place while Funtools is seeking to the specified input extension. This implies that the output file should be opened before any I/O is done on the input file or else the copy will fail. Note also that the copy of sub- sequent extension will be handled automatically by FunClose() if the output file is closed before the input file. Alternatively, it can be done explicitly by FunFlush(), but again, this assumes that the input file still is open. Upon success FunOpen() returns a Fun handle that is used in subsequent Funtools calls. On error, NULL is returned. SEE ALSO
See funtools(7) for a list of Funtools help pages version 1.4.2 January 2, 2008 funopen(3)
All times are GMT -4. The time now is 05:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy