Create a file if it does not exist when a script runs

I have a shell script I run using automator that puts on the clipboard a string like Page 001, Page 002 and so forth incrementing the number 00x everytime it runs. I use it when I need to sequentially name files when doing things like scanning documents and so forth.
Presently, I have to manually create a file "~/counter" and enter the integer to start counting from. So if ~/counter contains 0, pbcopy places "Page 001" on the clipboard and so forth
The shell script
<pre class="jive-pre">
#!/usr/bin/env bash
myvar=$(cat ~/counter);
let myvar=$myvar+1;
mycopy=$(printf "Page %03d" $myvar);
echo "$mycopy" | pbcopy;
echo "$myvar" > ~/counter;
</pre>
works fine now.
I want to modify the script so that if ~/counter does not exist, the script creates a file and initializes an integer value say 1 in the file. If the file exists, the script uses the integer used in the file.
How can I get this done?

And because I can not leave "Well Enough Alone"
#!/usr/bin/env bash
count=0
[[ -r ~/counter ]] && read count anyjunk_aftercount <~/counter
count=$((count+1))
echo "$count" >~/counter
printf "Page %03d" $count | pbcopy
The anyjunk_aftercount is just in case something else gets into ~/counter. Assuming the first non-blank field on line 1 is the count, then anything following the count will be stuffed into anyjunk_aftercount and since the script ignores it, it will go away when the script re-writes ~/counter with just $count

Similar Messages

  • "The file you selected does not exist" when the file definitely exists?

    Hi all,
    Using Contribute CS3 against Contribute Publishing Server--
    I have the site uploaded and set up within Contribute and
    CPS. But I am experiencing consistent &quot;The selected file
    does not exist&quot; errors whenever I try to open most
    documents within the site. I click the &quot;Choose&quot;
    button, navigate to a file -- I can see its contents in the
    &quot;Preview&quot; box within the Choose dialog -- and
    when I click &quot;OK&quot;, I get that file does not exist
    error.
    This is happening with most but not all files in my site
    tree. Trying to find a common denominator, it certainly does seem
    that files which trigger this error are all templated files.
    Non-templated files open fine.
    Contribute is configured to talk to the server (IIS) via
    WebDAV.. Am trying to get the sysadmins to enable FTP to see if
    this behavior also shows up then, but have not been able to get
    this done yet.
    Thanks all :-)
    Reuben

    Would I have been better off posting this in the General
    Discussion section? Could the moderators move it if so,
    please?

  • Service to checkin file if it does not exist, else version the file

    Hi All,
    From java layer I use WEBDAV and use PUT command and this command creates a new file if it does not exist, and if the file exists it versions the existing file.
    I have developed a java component to unzip a folder and checkin all individual files and folders into UCM whenever a zip file is checked in.I would like similar feature in my UCM component.i.e whenever files are unzipped they should always be versioned if they exist.I use the below code,but it always creates a new file(even if file with same name exists in the same folder)
    m_binder.setEnvironment(SharedObjects.getEnvironment());
    m_binder.putLocal("dDocName","");
    m_binder.putLocal("IsAutoNumber", "true");
    m_binder.putLocal("AutoNumberPrefix", "olm_");
    m_binder.putLocal("IdcService","CHECKIN_NEW");
    m_binder.putLocal("dDocTitle",entityName);
    m_binder.putLocal("xCollectionID",parentId);
    m_binder.putLocal("dDocType", "Document");
    m_binder.putLocal("dSecurityGroup","Public");
    m_binder.putLocal("dDocAuthor","sysadmin");
    m_binder.putLocal("dCreateDate","");
    m_binder.putLocal("primaryFile", entryName);
    executeService(ws, m_binder,"sysadmin",true);
    So, I would like to know, if there is a service to achieve the same or is there a parameter I can add in m_binder.putLocal to achieve the same? OR am I suppose to query the UCM Database to check for existence of the file and if it exists I need to manually check out and check it in?
    Thanks,
    Shwetha

    Thanks Fabian and Ryan for your feedback.
    So I queried db to retrieve the ddocName and if no rows are returned my code checks in new file. But if rows are returned I checkout the file using CHECKOUT_BY_NAME and then checkin using CHECKIN_UNIVERSAL using same ddocName.
    Creating/checking in new file is successful.
    For existing files the checkout is successful.I also confirmed the file is checked out by querying documenthistory and ensuring a new row is created with dction = 'Check out'
    But post checkout when i try to re-check using CHECKIN_UNIVERSAL command, I receive the below exception
    intradoc.common.ServiceException: !csUnableToCheckIn,OLM_002103!csCheckinItemExists
    at intradoc.server.ServiceRequestImplementor.buildServiceException(ServiceRequestImplementor.java:2115)
    at intradoc.server.Service.buildServiceException(Service.java:2326)
    at intradoc.server.Service.createServiceExceptionEx(Service.java:2320)
    at intradoc.server.Service.createServiceException(Service.java:2315)
    What am I missing here?
    Code snippet:
    m_binder.setEnvironment(SharedObjects.getEnvironment());
    m_binder.putLocal("IsAutoNumber", "true");
    m_binder.putLocal("AutoNumberPrefix", "olm_");
    String docName = getDocname(ws, parentId, entityName);
    if(docName != null && docName.equals("FILENOTFOUND")) {
    System.out.println("Creating new file");
    System.out.println("parentId is "+ parentId);
    m_binder.putLocal("IdcService","CHECKIN_UNIVERSAL");
    m_binder.putLocal("dDocName","");
    m_binder.putLocal("dDocTitle",entityName);
    m_binder.putLocal("xCollectionID",parentId);
    m_binder.putLocal("dDocType", "Document");
    m_binder.putLocal("dSecurityGroup","Public");
    m_binder.putLocal("dDocAuthor","sysadmin");
    m_binder.putLocal ("doFileCopy", "1");
    m_binder.putLocal("dCreateDate","");
    m_binder.putLocal("primaryFile", entryName);
    executeService(ws, m_binder,"sysadmin",true);
    System.out.println("Created file successfully");
    }else{
    System.out.println("Check out file");
    System.out.println("parentId is "+ parentId);
    m_binder.putLocal("IdcService","CHECKOUT_BY_NAME");
    m_binder.putLocal("dDocName",docName);
    executeService(ws, m_binder,"sysadmin",true);
    System.out.println("File checked out successfully");
    System.out.println("Check in file");
    m_binder.putLocal("IdcService","CHECKIN_UNIVERSAL");
    m_binder.putLocal("dDocName",docName);
    m_binder.putLocal("dDocTitle",entityName);
    m_binder.putLocal("xCollectionID",parentId);
    m_binder.putLocal("dDocType", "Document");
    m_binder.putLocal("dSecurityGroup","Public");
    m_binder.putLocal("dDocAuthor","sysadmin");
    m_binder.putLocal ("doFileCopy", "1");
    m_binder.putLocal("dCreateDate","");
    m_binder.putLocal("primaryFile", entryName);
    executeService(ws, m_binder,"sysadmin",true);
    System.out.println("Checked in file successfully");
    public String getDocname(Workspace ws, String folderId, String originalName)
    throws DataException,ServiceException
    System.out.println("Entered getDocname");
    String val = new String("FILENOTFOUND");
    String sql = "select a.ddocname from documenthistory a, docmeta b, documents d " +
    "where a.did = b.did and a.did = d.did and d.DORIGINALNAME = '" + originalName +
    "' and b.xcollectionid = '" + folderId + "'";
    System.out.println("sql query is : " + sql);
    ResultSet rs = ws.createResultSetSQL(sql);
    if(rs == null) {
    System.out.println("Resultset for getDocname is empty");
    throw new ServiceException("Resultset for getDocname is empty");
    DataResultSet result = new DataResultSet();
    result.copy(rs);
    if(result.getNumRows() >= 1) {
    result.first();
    val = result.getStringValue(0);
    System.out.println("ddocname is :" + val);
    return val;
    else {
    System.out.println("FILENOTFOUND");
    return val;
    Thanks,
    Shwetha

  • [SOLVED] ABS - nasm - install file (nasm.install) does not exist

    I was attempting to build the nasm package and I encountered the following error:
    ==> ERROR: install file (nasm.install) does not exist.
    When reviewing the PKGBUILD file there was a line in the header:
    install=nasm.install
    ArchWiki (PKGBUILD) explains the install directive
    The name of the .install script to be included in the package. pacman has the ability to store and execute a package-specific script when it installs, removes or upgrades a package. The script contains the following functions which run at different times
    I removed the install= line and everything appeared to work.  My question is... does anyone know if the install script it was expecting to find did anything special that is going to cause me grief going forward?
    Thx
    Last edited by dwardca (2013-07-06 04:43:41)

    I figured out what I did wrong.   I copied only the PKGBUILD file out of /var/abs/extra/nasm folder ..  the nasm.install was still in the folder.
    Explains why I couldn't find the answer on Google. 
    Last edited by dwardca (2013-07-06 04:44:13)

  • [SOLVED] database file for multilib does not exist

    Hey guys I ran into a problem today when I tried to install the proper packages I needed to use my wifi card. However when I tried to install it it gives me the error "database file for multilib does not exist" I can t seem to find out why I even tried chrooting into it and installing it that way with no luck. The package I tried to install was "pacman -S wireless_tools netcfg" thanks for the help guys you've been great.
    Last edited by bdawg (2012-09-18 22:57:17)

    bdawg wrote:
    Ok so the whole output is as follows:
    Warning: database file for 'multilib' does not exist
    Error: failed to prepare transaction (could not find database)
    And my Pacman.conf is blank
    pacman.conf and Pacman.conf (with capital 'P') are two different files. Double-check this.
    Are you running a 64-bit system?
    Your /etc/pacman.conf should look like this: https://projects.archlinux.org/pacman.g … an.conf.in but with some repositories configured: https://wiki.archlinux.org/index.php/Pa … positories
    Last edited by karol (2012-09-18 22:13:59)

  • File or Folder does not exist

    I'm having a wierd problem with a png image which generates an error in my script.
    I'm building a UI using the group constructor, here is the line code I'm using to load the image:
    myImg:Image{text:'',image:'(image_folder)/image.png', alignment:['left','top']}
    The script runs with one image but not another one which is also a png of the same dimensions, bit depth etc. For some reason I get the 'file or folder does not exist' error message. If I replace the image with a known good one the script works.
    I've re-generated the image a dozen times. Still no joy.
    I'm not a total noob, though I infrequently write scripts and am completely prepared to learn I've made totally maverick error.
    Any thoughts?

    myImg:Image{text:'',image:'(image_folder)/image.png', alignment:['left','top']}
    I'm assuming that "(image_folder)" is a placeholder or variable and you are concatinating for the file path to the image? When checking file paths for images or what not, I usually try...
    alert(File.decode(File.openDialog()));
    ...to verify that my path is correct. Sometimes there's a extra slash or something I am missing.

  • Part of Photoshop isn't functioning.  Under adjustments, when HDR toning is clicked on I get a code:  Error 48: File or folder does not exist.  Line:11  - $.evalFile(g_StackScriptFolderPath   "StackSupport.jsx");  How can it be fixed?

    The phone company was here working on something while I was gone.  They sat down at my computer (iMac) and since then HDR toning doesn't work.  Get the code:   Error 48: File or folder does not exist.    Line: 11     ->  $.evalFile(g_StacScriptFolderPatch + "StackSupport.jsx");   How can this be fixed?   

    Go to //Applications/Adobe Photoshop [Version]/Presets/ Scripts/Stack Scripts Only/ and see if StackSupport.jsx is there. If it is not, uninstall and reinstall Photoshop to have it added back in. If it is there, first try recreating the Photoshop Preferences (hold down Command+Option+Shift while launching Photoshop).

  • HDR Toning Error 48: File or Folder Does Not Exist

    After migrating to a new computer HDR Toning is no longer available.
    I get a pop-up: Error 48: File or Folder Does Not Exist
                             Line 11  -> $. evalFile(g_StackScriptFolderPath + "StackSupport.jsx");
    What's the fix for this, if anyone knows?
    Thanks.

    Go to //Applications/Adobe Photoshop [Version]/Presets/ Scripts/Stack Scripts Only/ and see if StackSupport.jsx is there. If it is not, uninstall and reinstall Photoshop to have it added back in. If it is there, first try recreating the Photoshop Preferences (hold down Command+Option+Shift while launching Photoshop).

  • Ruler Tool- Error 48: File or folder does not exist

    I am trying to use the new RULER TOOL in CS5 (64-bit mode) running 10.6.4 and I get the following error:
    Error 48: File or folder does not exist.
    Line: 31
    ->  $.evalFile( g_StackScriptFolderPath + "Geometry.jsx");
    Any ideas?

    i'm getting the exact error using Windows XP with CS5.5
    error 48: file or folder does not exist
    line: 31
    -> $.evalFile(g_StackScriptFolderPath + "Geometry.jsx");
    HELP!!!
    someone
    hello ... anyone out there?
    how do we get support for this error?
    e

  • Ressource file LM00    99 does not exist

    Hi all,
    I am getting an error while running LM00 in internet service in tcode se80.
    The error is : "Ressource file LM00      99 does not exist"
    I have done all the settings in SICF, as given in Raja's blog:
    Running your first  ITS WebGUI application in SAP NetWeaver 04 ABAP Edition - NSP
    and activated all services but still getting an error and not able to execute the code. However other standard tcodes are executing successfully. Only this Tcode Lm00 is not running.
    I'd greatful to all of u to solve this issue.
    Thanks
    Puneet

    Hi,
    Basically my error while running standard internet service for LM00 is:-
    The URL http://server2.XXXXX.local:8000/sap/bc/gui/sap/its/lm00/ was not called due to an error.
    Note
    The following error text was processed in the system PRO : Internal Error
    The error occurred on the application server server2_PRO_00 and in the work process 0 .
    The termination type was: TH_RES_FREE
    The ABAP call stack was:
    Module: %_CTL_OUTPUT_FLUSH of program SAPMSSYD
    Function: CALL_MESSAGE_SCREEN of program SAPLLMOB
    Form: ERROR_MESSAGE of program RLMENU
    Module: DYNAMIC_MENU_BUTTONS_TEXT of program RLMENU
    Form: CALL_SCREEN_MENU of program RLMENU
    START-OF-SELECTION of program RLMENU
    What can I do?
    If the termination type was RABAX_STATE, then you can find more information on the cause of the termination in the system PRO in transaction ST22.
    If the termination type was ABORT_MESSAGE_STATE, then you can find more information on the cause of the termination on the application server server2_PRO_00 in transaction SM21.
    If the termination type was ERROR_MESSAGE_STATE, then you can search for more information in the trace file for the work process 0 in transaction ST11 on the application server server2_PRO_00 . In some situations, you may also need to analyze the trace files of other work processes.
    If you do not yet have a user ID, contact your system administrator.
    Error code: ICF-IE-http -c: 100 -u: ABHATTA -l: E -s: PRO -i: server2_PRO_00 -w: 0 -d: 20081204 -t: 103603 -v: TH_RES_FREE -e: Internal Error
    HTTP 500 - Internal Server Error
    Your SAP Internet Communication Framework Team

  • Hi i am getting an error like this while installing Live Cycle Server " The file merge_modules\lc11_common_iam_zip does not exist This file is required sucessfullly run the  Live Cycle Installer.Can any one help me on resolving this issue it would be of g

    Hi i am getting an error like this while installing Live Cycle Server " The file merge_modules\lc11_common_iam_zip does not exist This file is required sucessfullly run the  Live Cycle Installer.Can any one help me on resolving this issue it would be of great help..thanks .

    I think in your situation it would be worth trying the things listed under the event. It does have to do with FRS and it's easy to do. I've used it to fix journal errors after a server unexpectedly restarts and sysvol stops replicating.  I
    could see where it could fix your issue, and if it doesn't, you're out 5 minutes. :)
    The listed registry key does not exist
    Expand HKEY_LOCAL_MACHINE. 
    Click down the key path: 
       "System\CurrentControlSet\Services\NtFrs\Parameters" 
    Double click on the value name 
       "Enable Journal Wrap Automatic Restore" 
     

  • SMC - "The management domain file...does not exist"

    Hi All,
    Just a quickie to see if anyone has seen this and has any pointers to getting out of it...
    Solaris 10 u5 x86. Machine has got SRSS4.0 running on it, the only other modification is CUPS is running in favour of the Solaris lp stuff (got instructions for this off a BigAdmin article).
    Anyways, I use SMC to manipulate user/group stuff on the local machine. SMC launches just fine, and I can gather System Information, view logs, disk configuration, processes etc. However, when attempting to do any user/group/role stuff management, I authentication with root role, click on the relevant panel, and get this:
    "The management server cannot perform the operation requested.
    If this problem persists, refer to the Log Viewer for additional information and contact your Sun Microsystems support provider.
    The actual error reported was:
    The management domain file:/shadowfire/127 does not exist or cannot be managed on server shadowfire."
    The behaviour is consistent. Gee, it was running fine before, AFAIK...
    Any pointers to what may have come unstuck gratefully appreciated, as always :)
    Dave

    I came across the same problem late July almost same day - on a brand new M4000 server with Solaris 10. I use an X-windows client to connect in and open Common Desktop Environment as "root". Then when I invoke SMC it works for everything except trying to open User Maintenance - then I get the error above.
    I came across something quite by accident whilst I was being advised to make edits to /etc/hosts (which I dont think made a difference anyway so I wont mention them)
    If I use my X-Windows client and open Common Desktop Environment as an ordinary user (say "joe") - then invoke SMC from the menu - when asked by the SMC utility to provide a logon then (as you would) enter the root username and password, guess what ! - I could open the User Maintenance icon without the error appearing and make changes and save them.
    Funny how a less privileged user than root invoking CDE seems to provide a basis to get the option to work! I still get the error by using CDE as root
    Wanna Try it?

  • User gets "This network connection does not exist" when she tries to log on to Terminal Server (2008 R2)

    User gets "This network connection does not exist" when she tryes to log on to Terminal Server (2008 R2)
    I got more than 100 users. Shes the only one getting is. We tried four computers (All Windows 7 Pro)
    Nothing useful in event viewer to mention.

    Hi,
    Thank you for posting in Windows Server Forum.
    Does that user able to login previously?
    From your comment, it seems that there is some permission issue with that user. As you have checked that user with different system also. Please check that user is added under “Remote Desktop User” local group and also allowed “Allow log on through
    Remote Desktop service” permission under group policy. Also please check that when user tries to login it uses “Domainname\Username” format.
    In addition for a try, also check by disabling firewall on one particular system.
    To add users and groups to the Remote Desktop Users group by using Local Users and Groups snap-in:
    1.  Click Start > Administrative Tools, Open Computer Management.
    2.  In the console tree, click the Local Users and Groups node.
    3.  In the details pane, double-click the Groups folder.
    4.  Double-click Remote Desktop Users, and then click
    Add.
    5.  In the Select Users dialog box, click Locations to specify the search location.
    6.  Click Object Types to specify the types of objects you want to search for.
    7.  Type the name you want to add in the Enter the object names to select (examples) box. 
    8.  Click Check Names.
    When the name is located, click OK.
    More information:
    Remote Desktop disconnected or can’t connect to remote computer or to Remote Desktop server (Terminal Server) that is running Windows Server 2008 R2
    http://support.microsoft.com/kb/2477176/en-us
    Hope it helps!
    Thanks,
    Dharmesh

  • Windows Server 2008R2 running Remote Desktop Services reports printer process does not exist when installing PDF printer

     Windows Server 2008R2 running Remote Desktop Services reports printer process does not exist when installing PDF printer, And when Installing network printers from the domain controller it reports it cannot connect to printer.  I can ping all
    network devices. I can connect to the internet.
    On boot I get a netlogon 5719 error followed by service control manager errors 7023,7001 and a group policy error 1129.
    Clients can connect to the remote application and RDP operates to connect to the server internally and externally.
    The domain controller is another server 2008r2 box. I have scoured the internet but have not found any solutions that work yet.

    Hi,
    After referring to your post, it can be identified that the issue which you are facing is mostly due to some network issue in your environment. Please recheck your network connection issue between computer and domain controller. 
    Can you able to ping with IP address and also with fully qualified name of a domain controller in the users' and computers' domain. If it fails states that name resolution issue with computer and domain controller. Are you using MS DHCP Relay agent then there’s
    available Hotfix for the particular Event ID. Please go through this KB 2459530 to fix the error event ID.
    As per the net logon error 5719 which you are facing states that the client component of Netlogon was unable to locate a DC for the domain it was trying to perform an operation against. Below is one of the reason. If this is being logged on a DC and the event
    refers to the DC's own domain, something might be preventing the client component of Netlogon from starting a network session (to itself or to another DC in the domain). The following event 7001 & 7023 states start & stop operation service. Please
    go through beneath article for more details.
    1.  Event ID 5719 is logged when you start a computer
    2.  Netlogon 5719 and the Disappearing Domain [Controller]
    3.  Event ID 1129 — Microsoft-Windows-GroupPolicy
    Hope it helps!
    Regards.

  • Adobe Reader plugin :This sentence "le fichier ne commence pas par '%PDF-'" appears when I try to open some (not all) PDF files within Firefox (does not happen when I download the file)

    This sentence (in french version) "le fichier ne commence pas par '%PDF-'" appears when I try to open some (not all, mainly bigger than 1Mo) PDF files within Firefox (does not happen when I download the file)

    You mention Thunderbird, has the PDF file been emailed to you? If it has this support page from Adobe may help - http://www.adobe.com/fr/support/toptech/acrobat/319294/

Maybe you are looking for