Unix script to check file exist in the directory for more then 30 min then user get the notification email - unix

I am searching for a UNIX script to check files in directory and if file exists then I have to compare the time with current timestamp. whether file stays in directory for more then 30 min then user will get an notification email.

Newer versions of find command will allow something like this:
find . -cmin +30 | while read file ; do executeTooOldFile "$file" ; done
However, you need to think this through. If you run this every minute, then until the file is removed, the user will get an email every minute. Maybe your test should be "-amin +30" and then you 'touch' the file (that would change it's timestamp though) so you won't send an email for another 30 minutes.
Note: 'find' and 'touch' are system commands but 'executeTooOldFile' would be your own script that includes what to do when you found too old a file. If you have access to 'cron' then you can schedule the find command directly in it, but I would create a "master" script that would contain the 'find' and execute that in cron.

Related

How to stop retyping "ssh user#domain.com" over and over

My workflow always consists of opening a new terminal window, typing ssh user#domain.com (or scp) followed by cd remote/directory/of/project
The domain is long and hard to type, as well as it being a big file path so this takes me ~20 seconds every time. What's the canonical, efficient way to do this that you would see a senior dev doing?
For not retyping ssh user#domain.com that often, you can put it in you .ssh/config:
Host my_alias
HostName domain.com
User user
Afterwards, you can just type ssh my_alias.
For not retyping the path, you can
put the path in an alias in your .bashrc (alias cd_my_proj='cd remote/directory/of/project')
look it up in your bash history (usually with Ctrl+R)
use a soft link (ln -s remote/directory/of/project ~)
keep the path open in a tmux (or screen) session
You may also google these pointers for more details (like how to save tmux session and further details in your .ssh/config)
You can create a script file with the commands you want to execute so you can just execute it instead of manually typing your ssh/scp/cd commands every time you have to do so.

How to transfer an XFB file using command BTOPUT in unix server

We have one .sh file which contains all the configurations.
We have something like this,
export MARK_REMOTE_NODE= (server name)
The requirement is we have to send the same file to two different servers.Is it possible to transfer the same XFB file to different REMOTE_NODE or servers in UNIX??
When i was searching i got to know that BTOPUT transfers are one file at a time to one Partner.So can anyone tell me how to transfer file to 2 different servers?
XFB already has a hard job matching different operating- and filesystems with optional compression and retry mechanism. You want some logic what will happen when 1 transfer fails (only send second when first succeeds, shoot-and-forget, always try to send both and trust your incident management to catch the errors thrown by your monitoring, wait for async transfer for time depending on filesize,..).
I wouldn't trust the XFB options and just make a loop in your script doing exactly what you want. The additional advantage is that a migration to another communication tool will be easier.
while read -r targethost; do
# You need a copy, since xfb will rename and delete the file
cp outputfile outputfile.${targethost}
my_send_xfb ${targethost} outputfile.${targethost}
# optional check result posting the file in the queue
if [ $? -ne 0 ]; then
echo "Xfb not ready or configured for ${targethost}"
# Perhaps break / send alert / ..
fi
done < myhosts

Change authorization level when initializing sas batch job

I run SAS batch jobs on a UNIX server and usually encounter the problem that I cannot overwrite sas datasets in batch that have been created by my user locally without changing the authorization level of each file in Windows. Is it possible to signon using my user id and password when initializing the batch job to enable me to get full authorization (to my own files) in batch?
Another issue is that I don't have authorization to run UNIX commands using PIPE on a local remote session on the server and can hence not terminate my own sessions. It is on the other hand possible to run PIPE in batch, but this only allows me to terminate batch jobs so I also wonder if it is possible to run a pipe command in batch using my id and password as the batch user does not have authorizatio to cancel "local remote sessions" on my user?
Example code for terminating process:
%let processid = 6938710;
%let unixcmd = "kill &processid";
%PUT executing &unixcmd;
filename unixcmd pipe &unixcmd.;
there's a good and complete answer to your first point in the following SAS support page.
You can use the umask Unix command to specify the default file permission policy used for the permanent datasets created during a SAS session (be it batch or not).
If you are lauching a Unix script which invokes a SAS batch session you can put a umask command just before the sas execution.
Otherwise you can adopt a more permanent solution including the umask command in one of the places specified in the above SAS support article.
You are probably interested in something like:
umask 002
This will assign a rw-rw-r-- file permission to all new datasets.

Search for a folder using applescript

I am trying to make a folder to go on a server, that people can add photos to and then the script sends them to the correct place, however I'm having trouble with the search part.
As you can see below in my code, the part where it finds where to send the folder to is commented out, because I have no idea what the syntax is for it.
Any help would be greatly appreciated.
global theWatchedFolder
set theWatchedFolder to choose folder
on idle
tell application "Finder"
set theDetectedItems to every item of theWatchedFolder
repeat with aDetectedItem in theDetectedItems
set jobNumber to display dialog "Please enter the job number for this photo." buttons {"Submit", "Cancel"}
display dialog "File detected: " & jobNumber
--tell finder
-- search for jobNumber in (path to desktop)
--set jobFolder to top search result
--end tell
--set colourFolder to jobfolder & /colour
move aDetectedItem to the desktop --move to colourFolder
end repeat
end tell
if theDetectedItems is not {} then
activate
display dialog "test move complete"
end if
return 1
end idle
Also, I am concerned that if this script is on the server, watching a folder on the server, then it won't create a pop-up for anyone who adds a file to the folder on the server. Hopefully I am wrong but if someone could confirm this one way or the other then that would be awesome. Thanks :)
I can confirm your biggest fear. The display dialog is shown in the Finder who is targeted. You'll always address the Finder on the same machine that is running your script, unless your using remote events. If the script is running on the server, the dialog will appear in the Finder running on the server.
I have also a side note that you continuously keep running AppleScript using an idle handler to check for any updates in a particular folder. Did you know that AppleScript has memory leaks as an stay open application? It's software you don't want to run constantly on a server. It's better to start a new AppleScirpt in a new process once in a while (I prefer something like every hour) and quit the current running one. You can still use the idle handler but if the idle handler runs every 10 seconds I would quit this script and start a new one after 600 loops.
Then back to your search. Finder doesn't have a search command. Since Mac OS X Tiger Apple introduced spotlight, a meta database for finding different kind of data (files, bundles, mails, etc). However spotlight has never been scriptable but for AppleScript only accessible on the command line using mdls, mdfind and mdutil. To execute commands on the command line we use the do shell script command in AppleScript or do script command for scripting the Terminal.app. Here an example of how to use with a do shell script command
set theFolder to choose folder
set searchKey to "the*" --use * as wild card
findMetaDataInFolderByName(theFolder, searchKey)
on findMetaDataInFolderByName(HFSPath, searchKey)
set options to " -onlyin " & quoted form of POSIX path of HFSPath
set options to options & " \"kMDItemFSName == " & quoted form of searchKey & "\""
return paragraphs of (do shell script "mdfind " & options)
end findMetaDataInFolderByName
note: because we're working in the shell the paths returned are posix path which can be used anywhere by prefixing the path with posix file
But, you have mentioned that the search has to be invoked on a server. Normally when your have a server properly installed the shares are outside the application and user home folder. These folders are by default only indexed by spotlight so spotlight needs to index on the fly. In other words it's very slow compared to normal spotlight searches with are done in less than a second. So I would suggest another version of the same script as above but using find. Find will simply walk recursively to the given directory and print every match.
set theFolder to choose folder
set searchKey to "the*" --use * as wild card
findFilesInFolderByName(theFolder, searchKey)
on findFilesInFolderByName(HFSPath, searchKey)
--the HFSPath can't have a trailing "/"
set UFSPath to POSIX path of HFSPath
if UFSPath ends with "/" and UFSPath is not "/" then set UFSPath to text 1 thru -2 of UFSPath
set options to space & quoted form of UFSPath
set options to options & " -iname " & quoted form of (searchKey) --iname is case insensitive file name match
paragraphs of (do shell script "find " & options & " -print 2>/dev/null ; exit 0") --pipe error to /dev/null to exclude permission denied messages
end findFilesInFolderByName
note: A side effect is because find will try every file while meta data search works different you'll probably find more files now because folders are included in the search as well. Just like findMetaDataInFolderByName(), findFilesInFolderByName() will return posix paths.

How to check for existence of Unix System Services files

I'm running batch Java on an IBM mainframe under JZOS. The job creates 0 - 6 ".txt" outputs depending upon what it finds in the database. Then, I need to convert those files from Unix to MVS (ebcdic) and I'm using OCOPY command running under IKJEFT01. However, when a particular output was not created, I get a JCL error and the job ends. I'd like to check for the presence or absence of each file name and set a condition code to control whether the IKJEFT01 steps are executed, but don't know what to use that will access the Unix file pathnames.
I have resolved this issue by writing a COBOL program to check the converted MVS files and set return codes to control the execution of subsequent JCL steps. The completed job is now undergoing user acceptance testing. Perhaps it sounds like a kludge, but it does work and I'm happy to share this solution.
The simplest way to do this in JCL is to use BPXBATCH as follows:
//EXIST EXEC PGM=BPXBATCH,
// PARM='pgm /bin/cat /full/path/to/USS/file.txt'
//*
// IF EXIST.RC = 0
//* do whatever you need to
// ENDIF
If the file exists, the step ends with CC 0 and the IF succeeds. If the file does not exist, you get a non-zero CC (256, I believe), and the IF fails.
Since there is no //STDOUT DD statement, there's no output written to JES.
The only drawback is that it is another job step, and if you have a lot of procs (like a compile/assemble job), you can run into the 255 step limit.

Resources