使用crontab运行Makefile

时间:2016-07-22 15:49:22

标签: postgresql makefile crontab osmosis

我是Ubuntu和编程的新手。 我正在测试我在github上找到的程序,下载并将OSM数据导入postgis。 当我从终端运行它时(url和名称是假的):

make all NAME=dbname URL='http://myurl'

使用postgres用户。

现在我需要每天运行此命令。 所以我写了那个剧本:

#!/bin/bash
# go to the directory with Makefile
cd /PCuserhome/directory/to/Makefile/
# run Makefile
make all NAME=dbname URL='http://myurl'

当我从终端运行它时它会起作用。

所以我以这种方式将它添加到crontab(postgres用户):

0,15,30,45 * * * * /PCuserhome/myscript.sh

它创建数据库,但可能无法运行渗透选择(渗透在所有用户的路径中)。 有什么想法解决这个问题?谢谢!

1 个答案:

答案 0 :(得分:1)

crontab命令仅在最小环境变量下执行,即

$PATH(无论如何都是debian),

因此,如果您依赖$PATH中的程序,它将会失败。 考虑指定渗透程序的绝对路径,无论它在何处被调用。

或者,您可以在脚本中更改export PATH="/my/bin:$PATH" 本身

* * * * * env > /tmp/env.txt

p.s。:您可以通过添加简单的cron作业来检查环境

  07-22 21:52:58.919 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: Late-enabling CheckJNI
  07-22 21:52:58.999 8068-8068/app.farhanfarooqui.vocaplayer D/ActivityThread: setTargetHeapUtilization:0.25
  07-22 21:52:58.999 8068-8068/app.farhanfarooqui.vocaplayer D/ActivityThread: setTargetHeapIdealFree:8388608
  07-22 21:52:58.999 8068-8068/app.farhanfarooqui.vocaplayer D/ActivityThread: setTargetHeapConcurrentStart:2097152
  07-22 21:52:59.689 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_FOR_ALLOC freed 98K, 38% free 9458K/15107K, paused 28ms, total 29ms
  07-22 21:52:59.719 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm-heap: Grow heap (frag case) to 23.134MB for 5487936-byte allocation
  07-22 21:52:59.779 8068-8069/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_CONCURRENT freed <1K, 28% free 14816K/20487K, paused 28ms+13ms, total 60ms
  07-22 21:53:00.049 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_FOR_ALLOC freed <1K, 28% free 14816K/20487K, paused 45ms, total 45ms
  07-22 21:53:00.109 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm-heap: Grow heap (frag case) to 34.914MB for 12352384-byte allocation
  07-22 21:53:00.209 8068-8069/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_CONCURRENT freed 0K, 18% free 26879K/32583K, paused 25ms+37ms, total 106ms
  07-22 21:53:01.399 8068-8069/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_CONCURRENT freed 6342K, 23% free 26931K/34823K, paused 94ms+31ms, total 246ms
  07-22 21:53:01.399 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 6ms
  07-22 21:53:01.749 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_FOR_ALLOC freed 1965K, 17% free 29144K/34823K, paused 42ms, total 42ms
  07-22 21:53:02.029 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_FOR_ALLOC freed 982K, 16% free 31356K/37063K, paused 62ms, total 79ms
  07-22 21:53:02.439 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_FOR_ALLOC freed 1965K, 12% free 34799K/39303K, paused 93ms, total 93ms
  07-22 21:53:02.789 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_FOR_ALLOC freed 982K, 9% free 37995K/41543K, paused 45ms, total 45ms
  07-22 21:53:03.409 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm-heap: Clamp target GC heap from 49.130MB to 48.000MB
  07-22 21:53:03.409 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_FOR_ALLOC freed 1965K, 10% free 41438K/46023K, paused 202ms, total 202ms
  07-22 21:53:03.879 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm-heap: Clamp target GC heap from 52.251MB to 48.000MB
  07-22 21:53:03.899 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_FOR_ALLOC freed 983K, 8% free 44633K/48263K, paused 54ms, total 66ms
  07-22 21:53:03.899 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm-heap: Forcing collection of SoftReferences for 2265244-byte allocation
  07-22 21:53:04.009 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm-heap: Clamp target GC heap from 52.243MB to 48.000MB
  07-22 21:53:04.009 8068-8068/app.farhanfarooqui.vocaplayer D/dalvikvm: GC_BEFORE_OOM freed 9K, 8% free 44623K/48263K, paused 110ms, total 110ms
  07-22 21:53:04.009 8068-8068/app.farhanfarooqui.vocaplayer E/dalvikvm-heap: Out of memory on a 2265244-byte allocation.
  07-22 21:53:04.009 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm: "main" prio=5 tid=1 RUNNABLE
  07-22 21:53:04.009 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:   | group="main" sCount=0 dsCount=0 obj=0x420616a0 self=0x42051a48
  07-22 21:53:04.009 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:   | sysTid=8068 nice=0 sched=0/0 cgrp=apps handle=1075238992
  07-22 21:53:04.009 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:   | schedstat=( 0 0 0 ) utm=133 stm=23 core=1
  07-22 21:53:04.009 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:636)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:484)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:813)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.content.res.Resources.loadDrawable(Resources.java:2822)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.content.res.Resources.getDrawable(Resources.java:1522)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:917)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:854)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:           at android.content.res.Resources.loadDrawable(Resources.java:2807)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
  07-22 21:53:04.029 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.view.View.<init>(View.java:3419)
  07-22 21:53:04.039 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.widget.ImageView.<init>(ImageView.java:120)
  07-22 21:53:04.039 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.widget.ImageView.<init>(ImageView.java:116)
  07-22 21:53:04.039 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at java.lang.reflect.Constructor.constructNative(Native Method)
  07-22 21:53:04.039 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.view.LayoutInflater.createView(LayoutInflater.java:593)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:318)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.app.Activity.setContentView(Activity.java:1925)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at app.farhanfarooqui.vocaplayer.MainActivity.onCreate(MainActivity.java:45)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.app.Activity.performCreate(Activity.java:5203)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.app.ActivityThread.access$700(ActivityThread.java:143)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.os.Handler.dispatchMessage(Handler.java:99)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at android.os.Looper.loop(Looper.java:137)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:           at android.app.ActivityThread.main(ActivityThread.java:4960)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at java.lang.reflect.Method.invokeNative(Native Method)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at java.lang.reflect.Method.invoke(Method.java:511)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer I/dalvikvm:     at dalvik.system.NativeStart.main(Native Method)
  07-22 21:53:04.069 8068-8068/app.farhanfarooqui.vocaplayer A/libc: Fatal signal 11 (SIGSEGV) at 0x00000e20 (code=1), thread 8068 (oqui.vocaplayer)
  07-22 21:53:04.069 8068-8116/app.farhanfarooqui.vocaplayer A/libc: Fatal signal 11 (SIGSEGV) at 0x0011428c (code=1), thread 8116 (oqui.vocaplayer)